unemployment Posted June 6, 2011 Share Posted June 6, 2011 <li id="feed_1"> <a id="feed_1_1" href=""> </li> var feed_1 = document.getElementById('feed_1'); if (feed_1) { alert(feed_1.firstChild.id); } Link to comment https://forums.phpfreaks.com/topic/238559-firstchild-fails/ Share on other sites More sharing options...
KevinM1 Posted June 6, 2011 Share Posted June 6, 2011 That doesn't tell us much. Where is your JavaScript being invoked in relation to your HTML? Link to comment https://forums.phpfreaks.com/topic/238559-firstchild-fails/#findComment-1225915 Share on other sites More sharing options...
Adam Posted June 6, 2011 Share Posted June 6, 2011 The first child is a text node for the line-break (see here for better explanation). You're better off using the children object which doesn't preserve white-space as nodes: alert(feed_1.children[0].id); Link to comment https://forums.phpfreaks.com/topic/238559-firstchild-fails/#findComment-1225961 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.