jQuery Syntax

jQuery syntax : Basically in jQuery, first of all, select the HTML element first and then perform an action on them.

Basic Syntax Of jQuery

Following is the jQuery syntax:

General syntax
    
   $(selector).action()
   

Let us understand it:

  • A $ sign is an alias of jQuery.
  • A selector basically provides information about the selected HTML element.
  • An action() is a jQuery action that will be performed on the selected HTML element.

let us introduce a jQuery simple example.

General Syntax

      $(document).ready(
   function(){
 });
    
Try it now

Source Code

          
            $(document).ready(function () {
  // Some code to be executed...
  alert("Hello World!");
});          
        
Try it now
    
 $(document).ready(
function(){
 // jQuery methods go here...
});
   

The $(document).ready(handler); - It is used to prevent jquery code from running before the document is finished loading. Here, the handler is a function that is passed inside the ready() method and it will be ready to execute when the DOM hierarchy has been fully constructed.

There is also a method for the document-ready event:

    
   $(function(){
 // jQuery methods go here...
});
   

Please keep in mind that both syntaxes are equivalent. Although the document-ready event syntax is easy to understand the source code.

Web Tutorials

jQuery Syntax
Html Tutorial HTML
Javascript Tutorial JAVASCRIPT
Css Tutorial CSS
Bootstrap 5 Tutorial BOOTSTRAP 5
Bootstrap 4 Tutorial BOOTSTRAP 4