jQuery filter()
by class and id
<!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(".intro,#outro").css("background-color", "yellow"); });/*from ww w . j a v a 2 s. co m*/ </script> </head> <body> <h1>Welcome to My Homepage</h1> <p>This is a test.</p> <p class="intro">I am from java2s.com.</p> <p id="outro">CSS HTML.</p> <p>This is another test.</p> </body> </html>