简体   繁体   中英

jQuery confliction with the menu

I'm working a site which is having a jQuery conflicting error. I tried few practices from the internet but I always failed. Please take a look at the script and teach me how I can solve this error.

/**


 * navigation.js


 *


 * Handles toggling the navigation menu for small screens.


 */


( function() {


    var container = document.getElementById( 'site-navigation' ),


        button    = container.getElementsByTagName( 'h1' )[0],


        menu      = container.getElementsByTagName( 'ul' )[0];





    if ( undefined == button || undefined == menu )


        return false;





    button.onclick = function() {


        if ( -1 == menu.className.indexOf( 'nav-menu' ) )


            menu.className = 'nav-menu';





        if ( -1 != button.className.indexOf( 'toggled-on' ) ) {


            button.className = button.className.replace( ' toggled-on', '' );


            menu.className = menu.className.replace( ' toggled-on', '' );


            container.className = container.className.replace( 'main-small-navigation', 'navigation-main' );


        } else {


            button.className += ' toggled-on';


            menu.className += ' toggled-on';


            container.className = container.className.replace( 'navigation-main', 'main-small-navigation' );


        }


    };





    // Hide menu toggle button if menu is empty.


    if ( ! menu.childNodes.length )


        button.style.display = 'none';


} )();

Thanks :)

You need to add "jQuery" on the end:

jQuery.noConflict();

(function( $ ) {
    // Your jQuery code here, using the $
})( jQuery );

Taken from: http://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/

Try this.

$j = jQuery.noConflict();

Now use $j wherever jQuery is needed to be used.

eg use jQuery code j$(...) wherever jQuery is needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM