menu

jQuery Syntax



jQuery Syntax : The Basic Idea about jQuery is to select the element(s) and perform the action on them. For selecting elements the selectors are used.


jQuery Syntax

:

The $ symbol is used to access the jQuery.
The basic example for jquery selector and action :

selector is used to select the element from the dom.
.action() performs the action on the selected element.

Example

jQuery Basic Example :


Try it ยป

Output

jquery basic syntax

jquery basic syntax

jQuery $(document).ready method

jQuery document ready event is used to prevent code run while your document ie. page is loading. It runs the code only when your document is completely loaded and ready.
This is used because some elements ie. selectors are created later in that case your code will not work for those
elements.

Best Example can suppose your code run first in head section and your element is loaded in footer later, in this case your code will not work.

example of document ready method :

or you can also use