$(document).ready best practices

When writing custom jQuery scripts that fire on page load, it's always good practice to call jQuery.noConflict() before the document ready function.

jQuery.noConflict();
jQuery(document).ready(function($) {
  /*YOUR CODE HERE*/
});

For jQuery Mobile, consider:

var $ = jQuery.noConflict();
$('[data-role=page]').live('pageshow', function (event) {
  /*YOUR CODE HERE*/
});

By doing this, you minimize conflicts with other jQuery scripts and plugins.

 

Programming Tags: