Change div text with jQuery Toggle

后端 未结 8 807
粉色の甜心
粉色の甜心 2021-02-01 04:07

When using slideToggle, how to change the Text close/show? I did a simple one, but cannot get the text change back.

Here is what I did:

8条回答
  •  佛祖请我去吃肉
    2021-02-01 04:39

    try this demo

    $(document).ready(function(){
    $('.open').toggle(function(){    
            $('.showpanel').slideToggle('slow');
            $(this).text('close');
    }, function(){
        $('.showpanel').slideToggle('slow');
        $(this).text('Show');
    });
    
        $('.open2').toggle(function(){
    
            $('.showpanel2').slideToggle('slow');
            $(this).text('close');
        }, function(){
            $('.showpanel2').slideToggle('slow');
            $(this).text('Show');
        });   
    });​
    

提交回复
热议问题