How to use OR Operation in jQuery Attribute Selectors?


Use comma to work with OR operation in jQuery Attribute Selector.

Example

You can try to run the following code to learn how to use OR operation in jQuery attribute selector:

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script>
         $(document).ready(function(){
           $('[myattr=demo][myid="sub1"],[myattr=demo][myid="sub3"]').css("background-color", "yellow");
         });
      </script>
   </head>
   <body>
      <div myid="sub1" myattr="demo">Java</div>
      <div myid="sub2" myattr="demo">HTML</div>
      <div myid="sub3" myattr="demo">Ruby</div>
   </body>
</html>

Updated on: 18-Dec-2019

132 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements