www.webdeveloper.com
Results 1 to 9 of 9

Thread: IE 7 can't getElementByTagName

  1. #1
    Join Date
    May 2009
    Posts
    3

    Unhappy IE 7 can't getElementByTagName

    hi,
    i coded this javascript:
    Code:
    <script language="javascript">
    function loadinalert(){
     var setItem = 2; // Set item to get information
     var container = document.getElementById("rootcontainer");
     var imgboxrows = container.getElementByTagName("imgbox");
     var imgrows = imgboxrows.length;
     var imgitem = imgboxrows.item(setItem).innerHTML;
    alert("The Rows are "+imgrows+" and the second item in imgbox is "+imgitem);
    }
    </script>
    <div id="rootcontainer">
    <imgbox><a href="imgurl0.php"><img src="img0.gif" border="1"></a></imgbox>
    <imgbox><a href="imgurl1.php"><img src="img1.gif" border="1"></a></imgbox>
    <imgbox><a href="imgurl2.php"><img src="img2.gif" border="1"></a></imgbox>
    <imgbox><a href="imgurl3.php"><img src="img3.gif" border="1"></a></imgbox>
    <imgbox><a href="imgurl4.php"><img src="img4.gif" border="1"></a></imgbox>
    <imgbox><a href="imgurl5.php"><img src="img5.gif" border="1"></a></imgbox>
    </div>
    <a href="javascript:loadinalert();">Action</a>
    My question is, what must i change to run this code in Internet Explorer 7 or higher?

    In Firefox i don't have any problems only in internet explorer 7 (IE7++)

    Thank for your helpings

    Daniel
    Last edited by pysio; 05-27-2009 at 12:26 PM.

  2. #2
    Join Date
    May 2009
    Posts
    150
    Well first of all there's no such tag as <imgbox> use a <span> or <div> with an id instead.

  3. #3
    Join Date
    Jun 2007
    Posts
    667
    container.getElementByTagName
    Unless that's a custom function, it's spelled incorrectly.

    getElementsByTagName

  4. #4
    Join Date
    May 2009
    Posts
    3
    That's not my problem
    i make a mistake in the real script there is an "s" in getElementsByTagName.

    And also I can work with imgbox because that is the Tag Name and I don't want to give any Tags Id's.

    Please give me more results for my question.

    greetings
    pysio

  5. #5
    Join Date
    Jun 2007
    Posts
    667
    Quote Originally Posted by pysio View Post
    That's not my problem
    i make a mistake in the real script there is an "s" in getElementsByTagName.
    The problem seems to be that I.E. won't read the innerHTML of non-standard tags. Perhaps you could use DOM methods to read the childNodes, unless someone knows another way.

  6. #6
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    getElementsByTagName is only suipposed to work with tags that actually exist in HTML. You can't invent your own tag names and expect it to work.

    The way that you can do it that will work is to use a class name within the div tags that you want to look for and then write a short getElementsByClassName function for those browsers that don't have one built in that will just extract those tags that have the specified class.

  7. #7
    Join Date
    Jun 2007
    Posts
    667
    Quote Originally Posted by felgall View Post
    getElementsByTagName is only suipposed to work with tags that actually exist in HTML. You can't invent your own tag names and expect it to work.

    The way that you can do it that will work is to use a class name within the div tags that you want to look for and then write a short getElementsByClassName function for those browsers that don't have one built in that will just extract those tags that have the specified class.
    That wasn't the problem mentioned. Getting the list of non-standard tags is no problem, bit only I.E. won't read their innerHTML (or DOM nodes ).
    I suppose one solution is to parse the innerHTML of the containing div.

  8. #8
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    You can not mix the languages. If you intend to use custom tags, that means you quit HTML and enter the XML field. In XML DOM there is no innerHTML method, as there are no HTML tags, there are XML tags, which is not the same thing. After all, innerHTML is not a standard DOM method at all.

  9. #9
    Join Date
    May 2009
    Posts
    3

    Thumbs up

    ok.
    now i made it with <span><a href . ....

    thanks for your help

    closed

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles