jQuery | element Selector

jQuery element selector is used to select and modify HTML elements based on the element name.

Syntax:

$("element_name") 

Example-1: This example selects the “h2” element and adds border to it.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Example-2: This example changes text color of “h2” element on button click.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
  
    <script src=
  </script>
  
    <script>
        $(document).ready(function() {
         $("button").click(function() {
            $("h2").css("color",
                   "green");
            });
        });
    </script>
  
</head>
  
<body>
  
    <h2>GeeksForGeeks</h2>
  
    <button>Change text color
  </button>
  
</body>
  
</html>

chevron_right



Before:

After:



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.