jQuery | [attribute=value] Selector

The jQuery [attribute=value] selector is used to select and modify HTML elements with specified attribute and value.

Parameter Values:

  • attribute: Used to specify attribute to find.
  • Value: Used to specify value to find.

Syntax:

$("[attribute=value]")

Example-1: This example selects the elements having id GFG and adds a border to it.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
  
    <script src=
  </script>
  
    <script>
        $(document).ready(function() {
            $("[id=GFG]").css(
              "border", "5px solid green");
        });
    </script>
  
</head>
  
<body>
  
    <h2 id="GFG">
      GeeksForGeeks
  </h2>
  
</body>
  
</html>

chevron_right


Output:

Example-2: This example changes the text color of elements having a class attribute with value GFG.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
  
<html>
  
<head>
  
    <script src=
  </script>
  
    <script>
        $(document).ready(function() {
            $("[class=GFG]").css(
              "color", "green");
        });
    </script>
  
</head>
  
<body>
  
    <h2 class="GFG">
      GeeksForGeeks
  </h2>
  
</body>
  
</html>

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.