Help! I have been into jQuery for about two weeks but I cannot solve this problem.
I am trying to lop "bad" branches off the DOM tree. A bad branch is defined as a branch that does not contain any appropriate anchor address located in "keeplist". I have been able to lop off bad leaves (VERSION 1). However, I have not been able to lop off "bad" branches. VERSION 2 is supposed to lop off the bad branches, but instead it lops off ALL branches. It is as if the "this" provided by "each()" refers to the whole set of branches and not to the particular instance supposedly provided by each(). VERSION 3 is also supposed to lop off the bad branches but as VERSION 2 it lops off ALL branches. "this" in VERSION 3 is obtained from the second argument of each(). // VERSION 1 removes the leaf located down many levels $(objectfoo).children().each(function(i){ $(this).find('a').not(keeplist).remove();}) // VERSION 2 supposed to remove bad branches // instead removes ALL branches var this2 ; $(objectfoo).children().each(function(ichild){ this2 = this ; // buffer if($(this2).find('a').not(keeplist)){$(this).remove();}}) // VERSION 3 supposed to remove bad branches // instead removes ALL branches var thischild2 ; $(objectfoo).children().each(function(ichild, thischild){ thischild2 = thischild ; // buffer if($(thischild2).find('a').not(keeplist)){ $(thischild).remove();}})