5/22/2012

Tips writing jQuery function for beginner

Wirting jQuery

   1:  //----------------------------------------------
   2:  //a shortcut code noConflict 
   3:  (function($) {
   4:      // do something on document ready
   5:  })(jQuery);
      
   7:  //a long code
   8:  $(document).ready(function() {
   9:      // put all your jQuery goodness in here.
  10:  });
     
  12:  //a shortcut code
  13:  $(function() {
  14:      // do something on document ready
  15:  });

Fix error Conflict between many javascript library

//----------------------------------------------
//(noConflict) see reference site: http://api.jquery.com/jQuery.noConflict/
//Many JavaScript libraries use $ as a function or variable name,
//just as jQuery does. In jQuery's case, $ is just an alias for jQuery,
//so all functionality is available without using $.
//If we need to use another JavaScript library alongside jQuery,
// we can return control of $ back to the other library with a call to $.noConflict():
$.noConflict();
//or
jQuery.noConflict();
// Code that uses other library's $ can follow here.

Multiple $(document).ready() in one javascript file

$(document).ready(function() {
    // some code here
});
$(document).ready(function() {
    // other code here
});

Function define in one $(document).ready block and call outside another $(document).ready block

var demoFunction;
$(document).ready(function() {
    // some code here
    demoFunction = function() {
        // some function that does stuff
    };
});

$(document).ready(function() {
    demoFunction();
});

continuous….

Categories:
If You Enjoyed This Post Please Take 5 Seconds To Share It.

0 comments:

Post a Comment

 
  • Followers