jQuery Syntax and jQuery Selector

All jQuery methods or functions are called in side the $(document).ready(function(){ }); statement

$(document).ready(function(){

  // jQuery methods go here...

});

This function ensures that the jQuery is code never executed before the whole document is loaded first and ready.

Above the jQuery Syntax for loading and executing the jQuery Code can also be used as below

$(function(){

  // jQuery methods go here...

});

jQuery Selectors

jQuery selects a DOM element in the HTML doucment and then manipulate it.

Syntax for jQuery selector is: $(selector).action()

A $ sign to define/access jQuery
A (selector) to "query (or find)" HTML elements
A jQuery action() to be performed on the element(s)



Examples:

$(this).hide() - hides the current element.

$("p").hide() - hides all <p> elements.

$(".myclass").hide() - hides all elements with class="myclass".

$("#myid").hide() - hides the element with id="myid".