Jquery collisions
Using Jquery and other libraries together can cause naming collisions. These are mainly from libraries using the $ (dollar sign) to prefix variables. This can be avoided using the following statement.
jQuery.noConflict();
We then follow on the code with the following example:
jQuery(document).ready(function() {
JQuery('#nav_products li').each(function() {
if (!JQuery(this).hasClass('active')) {
JQuery(this).find('ul').hide();
}
});
}
That's all nice but we start using the text JQuery throughout our code. What we need to do is make sure there isn't any collisions with other javascript libraries and also use the $. This can be done by placing a $ within the function parameters.
jQuery(document).ready(function($) {
Our code now becomes:
jQuery.noConflict();
jQuery(document).ready(function($) {
$('#nav_products li').each(function() {
if (!$(this).hasClass('active')) {
$(this).find('ul').hide();
}
});
}
No more collisions and clean code.