Javascript examples for jQuery Method and Property:filter
Filter selected elements by element name and class name
<!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($("div p.intro")).css("background-color", "yellow"); });//w w w . j av a 2 s . c om </script> </head> <body> <div style="border:1px solid black;">This is a div element <h1>Welcome to My Homepage</h1> <p>test</p> <p class="intro">test(will be selected).</p> <p>test</p> </div> <p class="intro">This p element is outside the div element.</p> <p>This p element is also outside the div element.</p> </body> </html>