JavaEar 专注于收集分享传播有价值的技术资料

What to use instead toggle?

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/

1个回答

    最佳答案
  1. 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');
         });
    });