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