JQuery syntax is used to construct the JQuery statements. Its having set of rules to construct. By following these rules, we can easily write a programs on JQuery.
The typical jQuery syntax having the elements and actions.
Here the $ sign denotes to define or access the JQuery library.
The selector denotes elements and
The action() denotes to be perform some actions on the selected element(s).
JQuery Syntax Example :
// Some code to be executed…
alert(“My First JQuery Syntax Example”);
The $(document).ready(handler) statement represents the ready event. It executes when ever the DOM loaded successfully; and here handler is an callback function.The handler function will execute, when the document finishes its execution and ready to manipulate.
Example JQuery Program :
The above program consist of the element, and function executed on that element. The element is document for the above program and the function having the selector (“p”). The line specifies the selector to select the text in the paragraph in the document.
Inside the function we can have number of syntaxes to handle any of the jQuery events, selectors or the effects. These are briefly studied after. For instance :
The above code specifies click() event. Which is fired when ever the button is clicked and as per the logic inside the function it changes the DOM element <p> with given text.