View Full Version : AJAX DOM problem-Is it possible to simulate getElementsByTagName() w/ getElementById?

03-18-2007, 12:53 PM

Currently I am experiencing a problem with the referencing getElementsByTagName(), because I am using AJAX to load page content dynamically and write into a DIV-container using its property innerHTML.

The point is by this way one can only reference to objects using getElementById(), because they are not automatically being included into the DOM, unless by a DOM-parser which is not cross-browser standard yet as far as I know.

Is it possible to overwrite and simulate the function getElementsByTagName() or replace in any way?

Best regards

03-18-2007, 05:43 PM
Actually, once the Ajax added content has been fully loaded, getElementsByTagName should work. However, if you are targeting the members of a getElementsByTagName collection by number, ex:


The number 0 which refers to the first span on the page may no longer point to the element that you have in mind.

If all you are after is a single element, getElementById will work fine. If you need a number of elements, getElementsByTagName should be fine but you may need another way to determine which of the tags that this 'gets' are the ones that you want to act on.