When I load this page I get behaviour I cannot understand
The first time I click the button all the elements get reversed. Each
subsequent time only the <p> elements are reversed. Because the
function "process" only gets 'p' elements i expect it to leave the
button and link alone.
I am a beginner at Javascript and am confused.
<head>
<title>Dom Hack</title>
<script>
function process(n){
var kids = n.getElementsByTagName("p");
var numkids = kids.length;
for(var i = numkids-1; i >= 0; i--) {
var c = n.removeChild(kids[i]);
n.appendChild(c);
}
}
</script>
</head>
<body>
<p id="a">Paragraph #1</p>
<p id = "b">Paragraph #2</p>
<p id = "c">Paragraph #3</p>
<button onclick="process(document.body);">Click Me to reverse</button>
<br/>
<a href="#" id="link1" >Link</a>
</body>
Worik