Javascript examples for jQuery Method and Property:filter
The filter() method gets elements by a certain criteria.
Parameter | Require | Description |
---|---|---|
criteria | Optional. | a selector expression, a jQuery object or one or more elements |
function(index)? | Optional. | a function to run for each element in the set. |
The following code shows how to Return all <p> elements with class name "intro":
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").filter(".intro").css("background-color", "yellow"); });/*from ww w .j a va2 s. c om*/ </script> </head> <body> <p>test</p> <p class="intro">test</p> <p class="intro">test</p> <p>test</p> </body> </html>