November 28, 2012 TXAD

Using jQuery noConflict

Here is a little tip for everyone out there when adding various javascript libraries to a website.

When using two or more different Javascript libraries, typically you’ll run into an issue where they both try to utilize the $ function inside their protocols. When this happens, the browser will run one and render the other one null or useless. The general way around this is to find different plugins that all use the same javascript library, but sometimes that’s not feasible. How do you get around it?

Well, if one of your javascript libraries is jQuery, you have a method built right in. Instead of utilizing the $ call in your function, you can instead switch it out for the term “jQuery”. If you don’t want to modify ALL of your code, an easier way is to include both library .js files, and then in your script tag, write “$.noConflict();” at the very beginning. This will allow you to put both types of code in and allow them to work harmoniously!

Now you know, and knowing is half the battle!

Tagged: , , , , ,