DOM - nodes parcourt
/Html JavaSript/DOM - nodes parcourt.html
<html>
<head>
<script type="text/javascript">
function foo() {
Aff(document.getElementById('TheBody'));
}
function Aff(n) {
var i, attr, txtAttr='';
if (n.nodeType==1) { // ELEMENT_NODE = 1
for (i=0; i<n.attributes.length; i++) {
attr = n.attributes[i];
if (attr.value != 'null' && attr.value != '') { // pour qu'IE aff pas tout
txtAttr += '\n' + attr.name + ' = ' + attr.value;
}
}
alert(n + '\n' + txtAttr);
/*
//-- travail sur les attributs :
if(n.getAttribute('oncontextmenu')){
n.removeAttribute('oncontextmenu');
n.setAttribute('align', 'center');
}
*/
// descente récursive :
for (i=0; i<n.childNodes.length; i++) {
Aff(n.childNodes[i]);
}
}
}
</script>
</head>
<body id="TheBody">
Parcourt l'arbre des nodes (DOM)
<table id="TheTable" border="1" oncontextmenu="return false">
<tr><td>foobar</td></tr>
</table>
<form action="azerty.php">
<input type="button" value="parcourt" onclick="foo()">
</form>
</body>
</html>