Results 1 to 2 of 2

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

  1. #1
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question AJAX DOM problem-Is it possible to simulate getElementsByTagName() w/ getElementById?

    Hi,

    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
    Philipp

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    document.getElementsByTagName('span')[0]
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •