jQuery toggle and IF visible

前端 未结 3 2149

I have a div which contains settings and options on an account management page.

$(\"#moreOptions\").slideToggle(\'slow\');
if ($(\"#moreOptions\").is(\":visible\         


        
3条回答
  •  无人及你
    2021-02-13 03:54

    You need to use the callback function. By the time the if statement is evaluated the slideToggle will not have completed and you will get incorrect results.

    $("#moreOptions").slideToggle('slow', callbackFn);
    
    function callbackFn(){
    
         var $link = $("#lnkMoreOpt");
    
         $(this).is(":visible") ? $link.text("Less Options «") : $link.text("More Options »");
    
    
    }
    

提交回复
热议问题