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
https://forums.phpfreaks.com/topic/110616-how-do-i-target/
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
https://forums.phpfreaks.com/topic/110616-how-do-i-target/#findComment-567497
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
https://forums.phpfreaks.com/topic/110616-how-do-i-target/#findComment-567502
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
https://forums.phpfreaks.com/topic/110616-how-do-i-target/#findComment-567518
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.