Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,982
    Thanks
    120
    Thanked 76 Times in 76 Posts

    getElementsByTagName,<a>, returns href instef of object ?

    can't correct title, so if admin have some time , please change insef to instead.

    Code:
       <DIV  id = "mi1">
               <a class = "mi" href="javascript:alert('a');">java script </a> 
               <a class = "mi" href="#n">aaaaaaaaaaaaaa </a>
               <a class = "mi" href="#n">ffffffffffff </a>
               ....
       </DIV>
    
       theThing = document.getElementById('mi1');
       theThingChilds = theThing.getElementsByTagName("a"); 
       for (i = 0; i <=  theThingChilds.length-1; i++)
       {
          alert(theThingChilds[i])
          // first element alerts "javascript:alert('a');", second ... ???   } 
       }

    Thanks for help.
    Last edited by BubikolRamios; 02-25-2007 at 09:23 AM.

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    e.g.
    Code:
    theThing = document.getElementById('mi1');
    theThingChilds = theThing.getElementsByTagName('a'); 
    for (i=0; i<theThingChilds.length; i++) {
    	alert(theThingChilds[i].firstChild.nodeValue); // [node object] [node value]
    }
    Last edited by Bill Posters; 02-25-2007 at 09:55 AM.

  • #3
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,982
    Thanks
    120
    Thanked 76 Times in 76 Posts
    To explain again: I want FF:"[ObjectHTMLAElement]", IE: "[Object]" to be returned in alert box.
    Whay this does not work in my code ? It works if I do it with DIV element or some other element.

    there is complet sample that returns wrong result:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html >
    <head >
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    <body >
    <DIV id = "mi1" >
    <!-- tag a coz this is only element that takkes css a:active, a:focus-->
    <a href="#n">hhhhhhhhhhhhm </a>
    <a href="#n">hkgffhgjkgfh </a>
    <a href="#n">fhgjkhgjkl </a>

    </DIV>

    <script language="javascript" type="text/javascript">
    theThing = document.getElementById('mi1');
    theThingChilds = theThing.getElementsByTagName('a');
    for (i = 0; i <= theThingChilds.length-1; i++)
    {
    alert(theThingChilds[i]);
    }
    </script>
    </body>
    </html>
    Last edited by BubikolRamios; 02-25-2007 at 11:09 AM.

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    what is being returned is an HTML-object, it just seems that browsers treat them differently when using alert. You can still access its properties, as with a div or anything else, why do you need it to alert something nonsensical?
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #5
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,982
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Seems you are right. Was hunting some other error, and come up with this, and things got even more complicated.
    Note: document.write produces same thing as alert. And it is not browser thing as far as I know(IE and FF works the same)

    Thanks for tip.


  •  

    Posting Permissions

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