Parse current document as the function parameter in JavaScript
Description
The following code shows how to parse current document as the function parameter.
Example
<!--from ww w. j a va2 s .co m-->
<html>
<head>
<script type="text/javascript">
function outputNodeProps(nd) {
if (nd.style) {
nd.style.backgroundColor="gray";
}
var children = nd.childNodes;
for(var i=0; i < children.length; i++) {
outputNodeProps(children[i]);
}
}
</script>
<body onload="outputNodeProps(document)">
<div id="div1">
<h1>Header</h1>
<p>P1.</p>
<p>P2</p>
<h2>Header 2</h2>
<p>P1.</p>
<p>P2</p>
</div>
</body>
</html>
The code above generates the following result.
Javascript Tutorial Check
Check if an element has a certain attribute...
Check the length of a NodeList for a div el...
Check the length of the array returned from...
Compare two nodes with isSameNode in JavaSc...
Determine the node type in JavaScript
Find out the difference between innerHTML a...
Check if an element has a certain attribute...
Check the length of a NodeList for a div el...
Check the length of the array returned from...
Compare two nodes with isSameNode in JavaSc...
Determine the node type in JavaScript
Find out the difference between innerHTML a...