How to avoid conflict between JQuery and Prototype

后端 未结 1 453
时光说笑
时光说笑 2020-12-01 14:37

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

相关标签:
1条回答
  • 2020-12-01 15:12

    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);
    
    0 讨论(0)
提交回复
热议问题