I want to retrieve all the nodes present in particular DIV element.see the below test page
(firefox)
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>
function processTags()
{
var chNodes = document.getElementById('foo').childNodes ;
console.log(chNodes);
console.log("------");
var chNodes = document.getElementById('foo').getElementsByTagName('*') ;
console.log(chNodes);
}
</script>
</HEAD>
<BODY onload="processTags();">
<div id="foo">
<!-- this is a comment -->this is some text ? <span>this is inside span</span>
<div><p>test</p>test<div>
</div>
</BODY>
</HTML>
But it does not give me comments tag.. what is the best way to retrieve all tags ??
The heart of the problem is that these methods…
… return elements, as indicated by their names. However, comments and text nodes are not elements. They are nodes, but not elements.
So you need to do some traditional old fashioned DOM scripting, using
childNodeslike Vincent Robert suggested. Since – as you indicate in your comment to him – that.childNodesonly goes one ‘layer’ deep, you need to define a recursive function to find the comment nodes: (I’m naming minedocument.getCommentNodes())