Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I learned that function toggle() is deprecated. So what can i use instead toggle for this example:

<div id="block" style="width: 200px; height: 150px; background-color: blue"></div>

<span id="click">hide</span>

?

$("#click").toggle(
            function(){
               $("#block").slideUp();
               $(this).html('show');
            },
            function(){
               $("#block").slideDown();
               $(this).html('hide');

            });

http://jsfiddle.net/2rERJ/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
496 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use click and slideToggle method.

$("#click").click(function(){
     var $block = $("#block"),
         $this = $(this);
     $block.slideToggle(function(){
         $this.text($block.is(':visible') ? 'hide' : 'show');
     });
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...