jQuery document ready shorthand

Last updated on

Below is the shorthand for $(document).ready()

$(function() {
    console.log( "ready!" );

If you receive an error in console Uncaught TypeError: $ is not a function, noConflict() is probably enabled. Try this instead.

jQuery(function() {
    console.log( "ready!" );

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 you need to use another JavaScript library alongside jQuery, return control of $ back to the other library with a call to $.noConflict(). Old references of $ are saved during jQuery initialization; noConflict() simply restores them.

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

Leave a reply

Your email address will not be published. Required fields are marked *