I want to retrieve all the nodes present in particular DIV element.see the below test page (firefox)
New Document <
You can use .childNodes
to retrieve all children instead of .getElementsByTagName('*')
which will only return child elements.
Here is a function to retrieve all descendants of a DOM node:
function getDescendantNodes(node)
{
var ret = [];
if( node )
{
var childNodes = node.childNodes;
for( var i = 0, l = childNodes.length; i < l; ++i )
{
var childNode = childNodes[i];
ret.push(childNode);
ret = ret.concat(getDescendantNodes(childNode));
}
}
return ret;
}
Usage:
getDescendantNodes(document.getElementById("foo"));