I have the following HTML:
<html>
<head><title>Title</title></head>
<body>
<div id='div2'>
<a href='#'>1</a>
<div id='div1'>
<a href='#'>2</a>
</div>
</div>
</body>
</html>
... and the following Javascript code that I run through Greasemonkey:
var nodes = document.body.getElementsByTagName('a');
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
node.parentNode.removeChild(node);
}
I would expect it to find and delete all A tags; instead, he finds the first, but not the second. As far as I can tell, he is having difficulty with how the second tag A is nested.
Can someone please let me know how to remove all tags using getElementsByTagName? There are reasons why I would prefer not to use XPath, if at all possible.
source
share