Maxim Yefremov
Maxim Yefremov

Reputation: 14165

hide elements after filter using jquery

Why this code don't hide selected elements:

$(selector).filter(function() {
     return true;
}).hide();

Although this code hides:

$(selector).hide();

How to hide elements using filter in jquery?

In this example I used simple filter, that always true - only for example.

Upvotes: 0

Views: 74

Answers (2)

Rituraj ratan
Rituraj ratan

Reputation: 10378

$(selector).filter(function() {
     return this; //here pass this to return filter object
}).hide();

Upvotes: 2

Jai
Jai

Reputation: 74738

instead of returning true return this so change this:

return true;

to this:

return this;

Upvotes: 2

Related Questions