jQuery filter()
by element
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").filter(document.getElementById("intro")) .css("background-color", "yellow"); });//from w ww. j a v a 2s .c om </script> </head> <body> <h1>Welcome to My Homepage</h1> <p>This is a test.</p> <p id="intro">I am from java2s.com.</p> <p>This is another test.</p> </body> </html>