View Full Version : Script yielding inconsistent results

02-10-2009, 10:29 AM
var arr = document.getElementsByTagName('iframe');
var i, len = arr.length;
for ( i = 0; i <= len; i++ ) {arr[i].parentNode.removeChild( arr[i] );}The problem is it does not work on all the elements on the page.
It removes some of them on a random base and then gives this error: "arr[i] has no properties".
I did an experiment with the script - added it as a bookmarklet, which showed that executing multiple instances of it does remove all elements. Question is why doesn't one run do all the work?

02-12-2009, 03:18 AM
Start removing them from the end first. Reverse your loop [length-1 to zero]