Jump to content

Ajax & <div> versus <id> tags


stockton

Recommended Posts

For some reason or other I have up until now believed that for Javascript(Ajax) to be able to update fields on a web page those fields had to be defined within <div> </div?> tags.

I now suspect that this belief is wrong and as long as those fields have a unique id their cantent can be accessed and updated via getElementById.

Link to comment
https://forums.phpfreaks.com/topic/53844-ajax-versus-tags/
Share on other sites

Take this a step further... by learning how to manipulate the DOM, you can apply AJAX actions to any element on the page. Divs are a good choice since they have no space in and of themselves, but referencing an element by hierarchy or name alone is possible. Any element that can be referenced through Javascript can be used as the recipient of an AJAX call.

Link to comment
https://forums.phpfreaks.com/topic/53844-ajax-versus-tags/#findComment-266199
Share on other sites

one issue with updating anything with an id tag.  If you try to innerHTML a block level item into an inline item, trouble:

<script>
// don't do this
document.getElementById('test').innerHTML = '<div>hello</div>';
</script>
<span id="test"></span>

--violation of well formed document

Link to comment
https://forums.phpfreaks.com/topic/53844-ajax-versus-tags/#findComment-268027
Share on other sites

one issue with updating anything with an id tag.  If you try to innerHTML a block level item into an inline item, trouble:

<script>
// don't do this
document.getElementById('test').innerHTML = '<div>hello</div>';
</script>
<span id="test"></span>

--violation of well formed document

 

Also, keep in mind that IE won't let you use innerHTML to write to certain elements (only read).

Link to comment
https://forums.phpfreaks.com/topic/53844-ajax-versus-tags/#findComment-268346
Share on other sites

and if you want to output data to the HTML page?

I am using document.getElementById("SlotsIssued").innerHTML = SlotsIssued;

will this work with IE.

I cannot test it as I am on a Linux box and unless one goes to the trouble of installing Wine etc etc IE does not work on Linux.

Link to comment
https://forums.phpfreaks.com/topic/53844-ajax-versus-tags/#findComment-268377
Share on other sites

Also, keep in mind that IE won't let you use innerHTML to write to certain elements (only read).

obsidian, you mean like elements that just wouldn't make sense for innerHTML, like tr, input, or maybe ul?  Probably li is allowed.  I never tried any of those, I always just use div.

 

Out of curiousity, what item can only be read by innerHTML but not written to?

Link to comment
https://forums.phpfreaks.com/topic/53844-ajax-versus-tags/#findComment-268508
Share on other sites

Also, keep in mind that IE won't let you use innerHTML to write to certain elements (only read).

obsidian, you mean like elements that just wouldn't make sense for innerHTML, like tr, input, or maybe ul?  Probably li is allowed.  I never tried any of those, I always just use div.

 

Out of curiousity, what item can only be read by innerHTML but not written to?

 

No, I mean that there are actually elements (specifically table elements other than <td>) that IE cannot write to using innerHTML (IE 6 at least). I don't typically link to Microsoft for references, but this one is actually addressed in their own support forums:

 

http://support.microsoft.com/kb/239832

 

CAUSE

The innerHTML property of the TABLE, TFOOT, THEAD, and TR elements are read-only.

Link to comment
https://forums.phpfreaks.com/topic/53844-ajax-versus-tags/#findComment-268887
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.