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); } Quote 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? Quote 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); Quote Link to comment https://forums.phpfreaks.com/topic/238559-firstchild-fails/#findComment-1225961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.