tinfanide Posted December 8, 2011 Share Posted December 8, 2011 <script>window.onload = function(){x = document.getElementsByTagName("span")[0].nextSibling;alert(x.childNodes[0].nodeValue);}</script></head><body><span>span</span>text</body> I want to get the value "text" but it is not within a tag.How can I access it in JS? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 8, 2011 Share Posted December 8, 2011 It's inside the body tag, so it's a child of the body. Link to comment Share on other sites More sharing options...
ShadowMage Posted December 8, 2011 Share Posted December 8, 2011 It would be a text node of the body element. So you'd have to loop through the children of the body element and check each text node. Note that every space, new line, or other character between any tag is a new text node. Link to comment Share on other sites More sharing options...
tinfanide Posted December 9, 2011 Author Share Posted December 9, 2011 So I can't use nextSibling, can I? Link to comment Share on other sites More sharing options...
ShadowMage Posted December 9, 2011 Share Posted December 9, 2011 I don't see a reason you couldn't. nextSibling should return text nodes, too. Try it, then you'll know if it works. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.