jQuery Syntax
jQuery syntax : Basically in jQuery, first of all, select the HTML element first and then perform an action on them.
jQuery syntax : Basically in jQuery, first of all, select the HTML element first and then perform an action on them.
Following is the jQuery syntax:
$(selector).action()
Let us understand it:
let us introduce a jQuery simple example.
Source Code
$(document).ready(function () {
// Some code to be executed...
alert("Hello World!");
});
$(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.