#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Posts
    29
    Rep Power
    0

    GetElementsByTagName not finding all tags


    I have this code and it worked in another instance but won't work now in an .asp page generated from xslt. That is, in another instance it printed all of the <a> tags innerHTML but now it only prints the first one.
    The <a> tags are in different fieldsets and forms and table cells.

    It is executed by a button with OnClick.

    function printMe() {
    var blah = document.body.getElementsByTagName('a');
    for(var i = 0; i < blah.length; i++) {
    document.write(blah[i].innerHTML.replace(/<b>.*<\/b>/gi,"") + '<br/>');
    }
    }
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,041
    Rep Power
    119
    Assuming i am correct about what your wanting to do; this should do the trick:
    Code:
    function printMe() {
    var blah = document.getElementsByTagName("body")[0].getElementsByTagName("a");
     for(var i = 0; i < blah.length; i++) {
      blah[i].innerHTML = blah[i].innerHTML.replace(/<b>.*<\/b>/gi,"") + '<br/>';
     }
    }

IMN logo majestic logo threadwatch logo seochat tools logo