...

View Full Version : Script yielding inconsistent results



martix
02-10-2009, 09: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?

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

Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum