Tag Archives: document ready not working
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).action();
selector is used to select the element from the dom.
.action() performs the action on the selected element.
Example
Output
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 :
$(document).ready(function(){ // write your code here... });
or you can also use
$(function(){ // write your code here... });