How to combine a class selector and an attribute selector with jQuery?

jQueryWeb DevelopmentFront End Technology

A jQuery Selector is a function which makes use of expressions to find out matching elements from a DOM based on the given criteria. We can easily combine a class selector and an attribute selector with jQuery.

You can try to run the following code to learn how to How to combine a class selector and an attribute selector with jQuery −

Example

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() {
         $('.myclass[reference="12345"]').css("background-color", "yellow");
      });
      </script>
   </head>
   <body>
       <table>
         <tr class="myclass" reference="12345">
            <td>Row 1 Column 1</td>
         </tr>
         <tr class="myclass" reference="43215">
            <td>Row 2 Column 1</td>
         </tr>
         <tr class="myclass" reference="54321">
            <td>Row 3 Column 1</td>
         </tr>
      </table>
   </body>
</html>
raja
Published on 08-Dec-2017 16:20:41
Advertisements