jQuery Syntax

jQuery syntax is predefined and can be used to select and manipulate HTML elements.



jQuery Syntax

Syntax:

$(selector).action();
  • The $ sign is used to access the jQuery function.
  • The $ sign is an alias to jQuery()
  • A (selector) is used to find and select the element from the DOM.
  • jQuery uses CSS syntax to select the element(s).
  • action() performs the action on the selected element(s).

You can use jQuery instead of a $ symbol because the $ symbol is a synonym of jQuery.

jQuery Example with HTML

Example:

<!DOCTYPE html>
<html>

    <head>
        <title>jQuery with HTML Example</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    </head>

    <body>
        <script>
            $(document).ready(function() {
                $("p").click(function() {
                    $(this).hide();
                });
            });
        </script>
        <p>This is sample text.</p>
    </body>

</html>

In the above example, the paragraph will disappear on click.



Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram

Keep W3schools Growing with Your Support!
❤️ Support W3schools