Jump to content

How do I target


atrum

Recommended Posts

Hello all,

 

I have been trying to figure out how to accomplish using java to write html to a specific section in the body of my page.

 

I want to use a function to call html and text, and place it in a specific area of the page.

 

So I have my function

 

<script type="text/javascript">
function test()
{
document.write("html to be inserted");
}
</script>

 

Now How do I get the onclick event to write to let's say to a table data tag in the body?

Link to comment
Share on other sites

the easiest way is to give the table tag an ID:

<td id="write2me"></td>

then...

<script type="text/javascript">
function test()
{
document.getElementById('write2me').innerHTML = "html to be inserted";
}
</script>

 

also...just me being picky...but JAVA is not the same as JavaScript

Link to comment
Share on other sites

Thank you for the assistance. Just one more question.

 

What if instead of targeting a td tag. could I target a <p> tag.

 

Also let me just explain what I am trying to do.

 

On my page, I have a menu with links to a seprate page. Each page is identical in terms of layout and style. The only difference is the contents of the body.

 

My goal is to keep the contents for all the pages in a seprate file all together, and only have 1 acutall html page.

 

The menu will actually contact javascript functions, that when pressed, replace the contents of the body, with the corrisponding content for that link.

 

 

Am I crazy or is this a practical solution?

Link to comment
Share on other sites

That's actually not a practical or sustainable architecture.  Good luck scaling something like that.  And what if someone has JavaScript disabled?  You're completely screwed in that case.

Link to comment
Share on other sites

Yeah, don't really on JavaScript being enabled for your page to work.

 

Also, JavaScript is not SEO friendly. So search engines won't be able to parse and index the contents of your pages if you load them that way.

 

On a side note, you can give any HTML element an ID, and access it with document.getElementById('the_id_here'). The innerHTML attribute will only work on elements that can have contents (so won't work on stuff like BR, HR, etc)

Link to comment
Share on other sites

I know it's already been said, but java != javascript. They are two different programming languages that do very different things, which means it can be confusing if you use the name of one when meaning the other.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.