Syntax of JQuery
In this post we are going to learn about syntax of jquery.
JQuery syntax work for 'selecting' HTML elements and the action to be performed on them.
Syntax : $(selector).action()
In the above syntax $ sign is to define/access jquery.
(selector) is to query of find the html elements.
action() is the action is to be performed on the selected elements.
Examples :
$(this).hide() - This will hide the current element.
$("p").hide() - This will hide all <p> elements.
$(".example").hide() - This will hide the elements with class="example".
$("#example").hide() - This will hide the elements with id="example".
Document Ready Event
In our previous code of hiding the text, you might have noticed that we have used :
$(document).ready(function(){
// jQuery methods go here...
});
This is to prevent the jquery code from executing before the document is finished loadin.
To prevent the execution of jquery prior to loading of the document, and alternative syntax can be used instead of $(document).ready(function(){});
$(function(){
// jQuery methods go here...
});
I hope you are now familiar with the syntax of jquery and ready to explore jquery in our next part of tutorial.
0 comments:
Post a Comment