> // 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();}}) >
Well to try and break it down, you're doing a logic check without using a function that returns a logical value. .not returns an array of jquery objects and I think as far as an if statement is concerned that would evaluate to true. You need to do somthing like: if($(this2).find('a').not(keeplist).size() > 0){$(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();}}) Same here.