jQuery Conflict Variables

    
Posted on 01.08.10 at 12:29 pm by Aaron

From time to time, you might run into a problem where you are using multiple javascript libraries and your javascript breaks. There is a very simple fix for this. At the top of the html, under and inside the <head> tag, you will have some script tags that are calling your javascript libraries. Now for ease of use, keep the jquery library first:

 

<script type='text/javascript' src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.pack.js"></script>

 

Something like that.
After that line, and before any other libraries that you decide to use, you need to put this line:

 

<script> 
var $j = jQuery.noConflict();
</script>


The $j can be what ever you want it to be, but this is what you will use in your javascript instead of the $. For example, if you wanted to get the value of a form element ( with id of author), instead of $('#author').val(), you would use $j('#author').val().
This will make sure all your jquery stuff still works, while allowing most other javascript libraries.


Aaron Scherer
PHP Developer

Comments (0)

Leave A Comment
 
 
 
 
 
Please type this word backwards: j4t9k