jQuery toggle and IF visible

前端 未结 3 2155

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 04:05

    I prefer not to use separate functions because when one function does not need to be used twice, it is waste of code.. i believe this is easier to understand when someone comes to it..

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

提交回复
热议问题