user12026752
user12026752

Reputation:

Why isn't the test in my jQuery filter function working as expected?

I used a function in filter to check whether the display mode is block but it's not working.

Here's my code:

$("#wrap_element").find("*").filter(function(){
    return this.css("display")==="block";
}).css("background-color","red");

Thanks.

Upvotes: 1

Views: 77

Answers (1)

isherwood
isherwood

Reputation: 61083

You have a console error that hints at the problem:

Uncaught TypeError: this.css is not a function

You need to use a jQuery object since you're calling a jQuery method on it:

return $(this).css("display")==="block";
// ----^^----^

Demo

Upvotes: 3

Related Questions