jQuery .ready() JavaScript provides the load event for executing code when a page is rendered. This event gets triggered when the download assets such as images has completed. However, most people want their script to run as soon as the DOM hierarchy has been fully constructed. jQuery provides the .ready() for just this purpose. This is the corresponding domready function in Mootools. $(document).ready(function() { // your code alert('Page: ' + $('title').html() + ' dom loaded!'); }); $(function() { // Handler for .ready() called. alert('Page: ' + $('title').html() + ' dom loaded!'); });
1
2
3
4
| $(document).ready( function () { // your code alert( 'Page: ' + $( 'title' ).html() + ' dom loaded!' ); }); |
1
2
3
4
| $( function () { // Handler for .ready() called. alert( 'Page: ' + $( 'title' ).html() + ' dom loaded!' ); }); |
1
2
3
4
5
6
7
| jQuery.noConflict(); ( function ($) { $( function () { // by passing the $ you can code using the $ alias for jQuery alert( 'Page: ' + $( 'title' ).html() + ' dom loaded!' ); }); })(jQuery); |
No comments:
Post a Comment