SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    167
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    firstChild Fails

    Code HTML4Strict:
    <li id="feed_1">
          <a id="feed_1_1" href="">
    </li>

    Code JavaScript:
    var feed_1 = document.getElementById('feed_1');
     
    if (feed_1)
    {
    	alert(feed_1.firstChild.id);
    }

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The firstChild will be a newline character. One way to get the first HTML child element would be:
    Code:
    alert( feed_1.getElementsByTagName( '*' )[ 0 ] );
    Also avoid global variable names that clash with IDs
    Tab-indentation is a crime against humanity.


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
  •