Umm... there seems to be a slight misunderstanding here.
In your first example (the commented-out one) the methods you are using will
not affect the DOM in any way, shape or form. The filter() method simplify
restricts the current element selection to those that match the specified
criteria.
In your second example your final method is remove() - which will physically
remove the current selection of elements (governed by the preceding
methods/selectors) from the DOM.

The filter() method modifies the collection of elements within the jquery
object, it does actually do anything with those elements.

As an example....

var x = $("#app_content_2356318")  //this selects the element with the
specified id
                //change the selection to be the DIV children of the element
with the specified id...
               .children('div')                     
                //change the selection to be the TABLE children of the
currently selected DIVs...
               .children('table')
                //modify the current selection of TABLEs to only keep those
that have a class of "removeMe"
               .filter(function(index){ return $(this).is('.removeMe'); }) 
               ;
// x now contains an array (list) of elements that can be inspected in
Firebug
// Now, whatever elements are still in the x collection (if any), remove
them from the DOM
// ie. physically remove the #app_content_2356318 > DIV > TABLE.removeMe
elements from your page...
x.remove();

Clear as mud?


Pluthos wrote:
> 
> 
> Thanks Klaus and Wizzud
> 
> I really don't know what the problem is. Here is the latest thing I
> tried.
> 
> // $
> ("#app_content_2356318").children('div').children('table').filter(function(index)
> { return false; }) ; // does not works with or without the index as
> parameter. Nothing is removed
> 
> $
> ("#app_content_2356318").children('div').children('table').remove() ; //
> works! The table is removed.
> 
> Really simple but I must be missing something crucial.
> Some background: I am using Greasemonkey and Firebug. I am not using
> the $(document).ready(function() {    because it does not seem to work
> with Greasemonkey.
> 
> Pluthos
> 
> 
> On Sep 10, 2:56 am, Wizzud <[EMAIL PROTECTED]> wrote:
>> Yes, I must admit I did not test the actual documented example - I was
>> heading more at the root of the problem, ie what wasn't working with
>> Pluthos' script that caused him to try the example in the first place!
>>
>>
>>
>> Klaus Hartl wrote:
>>
>> > Pluthos wrote:
>> >> Hi everyone,
>>
>> >> I am new to this group. I have been trying to get filter(function) to
>> >> work for a few days without success. My goal was to remove DOM
>> >> elements that did not belong to a pre-arranged array. Out of
>> >> desperation I tried the example given in the on line documentation at
>> >>http://docs.jquery.com/Traversing/filter#fn. The example is:
>>
>> >> $("p").filter(function(index) {
>> >>   return $("ol", this).length == 0;
>> >> });
>>
>> >> with the corresponding HTML code:
>>
>> >> <p><ol><li>Hello</li></ol></p><p>How are you?</p>
>>
>> >> THIS DID NOT WORK!
>>
>> >> Is it a bug in jQuery or am I doing something wrong? Could one of you
>> >> try this same example? Thank you.
>>
>> >> Pluthos
>>
>> > This is because a <p> element cannot contain a <ol> element and the
>> > filter like any other related selector simply does not match, because
>> > the browser's tag soup parser closes the <p> element before the <ol>
>> > starts.
>>
>> > As of lately this problem was discussed pretty often, see the following
>> > thread:
>> >http://groups.google.com/group/jquery-en/browse_thread/thread/e8790c0...
>>
>> > And the problem explained in more detail:
>> >http://groups.google.com/group/jquery-en/browse_thread/thread/50fa1b3...
>>
>> > --Klaus
>>
>> --
>> View this message in
>> context:http://www.nabble.com/filter%28fn%29-tf4411567s15494.html#a12589785
>> Sent from the JQuery mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/filter%28fn%29-tf4411567s15494.html#a12688139
Sent from the JQuery mailing list archive at Nabble.com.

Reply via email to