JQuery Toggle not working as it should

前端 未结 5 761
被撕碎了的回忆
被撕碎了的回忆 2021-01-23 17:08

I have a problem with JQuery Toggle.

I have the following code:

var $_ = jQuery;
$_(document).ready(function(){

$_(\"#sh-zone-buttons\").delegate(\"#sh-         


        
5条回答
  •  北荒
    北荒 (楼主)
    2021-01-23 17:21

    With your current code you are hiding #sh-zone-login-menu and then in your callback method making it visible again.
    Also, var $_ = jQuery.noConflict(); is the prefered way to assign jQuery's $ to a variable

    var $_ = jQuery.noConflict();
    
    $_(document).ready(function(){
    
      $_("#sh-zone-buttons").delegate("#sh-zone-button-login-menu", "click", function(event) {
        event.stopPropagation();
        event.preventDefault();
    
        $_("#sh-zone-login-menu").toggle();
        $_(this).toggleClass("current");
      });
    });
    

提交回复
热议问题