Skip to content Skip to sidebar Skip to footer

How To Avoid Conflict Between Jquery And Prototype

If a page has both JQuery and Prototype then I got conflict. There is a option to disable $ sign for JQuery so there is no conflict but, I have to use keyword JQuery instead of $.

Solution 1:

Use the noConflict method for jQuery and assign it to a new (short) variable. Use the new variable wherever you would have used the $ for jQuery.

var$j = jQuery.noConflict();

$j(function() {
    $j('#selector').each( .... );
});

or, if you don't need to mix Prototype/jQuery you can wrap all of your jQuery code in an anonymous function.

(function($) {
    // $ sign here is a parameter, which is set to jQuery 

    $(function() {
        $('#selector').each( .... );
    });
})(jQuery);

Post a Comment for "How To Avoid Conflict Between Jquery And Prototype"