web design and coding services with a huge twist of creativity.

Quick Tip: Using jQuery.noConflict()

Published 11 months ago in Blog, Web

If you’re using jQuery along with another Javascript Framework (such as Prototype) which also implements the $ variable, you can give back control over it to whichever library first implemented it by using the following code (right after including jQuery):

jQuery.noConflict();

Now, instead of using $ to select jQuery objects, you will be able to use jQuery:

var el = jQuery("#myID");

However, typing jQuery every single time you want to select something gets old real quick, so you can use this trick when declaring noConflict():

var $j = jQuery.noConflict();

This reassigns the reference to the jQuery object to whichever variable you want. In this example, you can now use $j instead of jQuery as a selector. You’ll be (at least) 10 times more productive now!

here 's what 2 people think:

  1. Very useful! Great Blog. Keep on. :)

  2. This little thing just saved my ass, thanks a lot!

drop me a line!

If your comment doesn't appear immediately after you submit it, it might be held for moderation. Sorry, all you can do is wait.

You can use these elements to write your comment.