JQuery fires the custom event called ready(), whenever DOM is loaded and ready for manipulation.
If you want to execute any kind of events, what should work from this ready() handler only.
There are different ways are there for using ready function in the JQuery. Here i am discussing three ways.
Way 1
// Standard. jQuery(document).ready(function () { alert('DOM Ready!'); });
Way 2
jQuery(function () { alert('Using this syntax also DOM is ready'); });
Way 3
jQuery(function ($) { alert('Here also DOM is loaded'); });
Output:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> // Standard. jQuery(document).ready(function () { alert('jqueryexamplecode.blogspot.com'); }); jQuery(function () { alert('Using this syntax also DOM is ready'); }); jQuery(function ($) { alert('Here also DOM is loaded'); }); </script> </head> <body> </body> </html>
Output:
JQuery Ready() function syntax and usage |
Post a Comment