jQuery Syntax



We have already learnt about selector concept in CSS. In CSS selector is used to visually style the HTML elements. In jQuery using selector we can add behavior to ELement.

Selector in jQuery :

Following is the syntax for jQuery Selector –

$(selector).action()

We are selecting the HTML element and then we are applying certain action or behavior to that element.

Sign Explanation
$ Dollar sign tells us that we are using jQuery
(selector) It is used to select or find the HTML element.
action() It is used to apply or perform action on HTML element.

Let’s see how it can be done using following table –
Example Explanation
$(this).hide() Hides the current element.
$("h1").hide() Hides all h1 heading elements.
$(".para").hide() Hides all elements with class="para".
$("#para").hide() Hides the element with id="para".

The Document Ready Event :

We can apply events and behavior to an HTML element only when our document is completely loaded in the browser. In order to prvent auto running code before document finished loading we need to write code in ready method.

$(document).ready(function(){

   // Write Methods and jQuery Code

});