How to use OR Operation in jQuery Attribute Selectors?

jQueryWeb DevelopmentFront End Technology

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>
raja
Published on 15-Dec-2017 13:23:25
Advertisements