jQuery | Syntax

It is used for selecting elements in HTML and performing the action on those elements.

Syntax:

$(selector).action()



  • $ sign: It grants access to jQuery.

  • (selector): It is used to find HTML elements.

  • jQuery action(): It is used to perform actions on the elements.
    1. Used to hide the current element.
      $(this).hide()
    2. Used to hide all <p> elements.
      $("p").hide()
    3. Used to hide all elements with class=”test”.
      $(".test").hide()
    4. Used to hide the element with id=”test”.
      $("#test").hide()

    Document Ready Event:

    • jQuery Methods are inside a Document ready event for easy reading of code.

      $(document).ready(function(){
      
        // jQuery Method
      
      });

      This is to check and stop the jquery before the document is finished loading. This method also allows you to have JavaScript code before the body of your document, in the head section.

    • Some actions that can fail if the method is run before the loaded document:
      Get the image size which is not loaded or hide element which is not created yet.

    • The shorter method for document ready:
      $(function(){
      
        // jQuery Method
      
      });


    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.