Wednesday 29 April 2015

jQuery Syntax

With jQuery, we can select HTML elements and perform some actions in it.

jQuery Syntax

The jQuery syntax is used to select the HTML elements and perform some action in it.

The Basic Syntax is : $(selector).action()
  • The $ sign is used to define or access jQuery
  • The (selector) is used to find or select HTML elements.
  • The action() is the jQuery action to be performed in the HTML element.
For example:
$("p").hide()

The Document Ready Event

The document ready event is used to prevent any jQuery code from running before the document had finished loading. It is good practice for the document to be loaded before working with it. This also allows you to place the jQuery code before the body of the document, that is in the head section.

For example:
$ (document).ready(function() {
   // jQuery method goes here...
});

The jQuery team has also created an even shorter method for the document ready event.

For example:
$ (function () {
   // jQuery method goes here...
});

0 comments:

Post a Comment