Open In App
Related Articles

jQuery element Selector

Improve Article
Improve
Save Article
Save
Like Article
Like

jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript. Elaborating the terms, it simplifies HTML document traversing and manipulation, browser event handling, DOM animations, Ajax interactions, and cross-browser JavaScript development.

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 a border to it. 

HTML




<!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>


Output: 

 

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

HTML




<!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>


Output:

 Supported Browsers:

  • Google Chrome 90.0+
  • Internet Explorer 9.0
  • Firefox 3.6
  • Safari 4.0
  • Opera 10.5

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 06 Jul, 2023
Like Article
Save Article
Similar Reads
Related Tutorials