Using jQuery .live with toggle event

后端 未结 4 697
抹茶落季
抹茶落季 2020-12-01 01:29

My code is working, but requiring me to click twice to active my chaining (once for the click event, and once for the toggle event.) What can I do to make it so I only have

4条回答
  •  有刺的猬
    2020-12-01 02:07

    //Show or Hide Comments
    $('#showHideComments').live('click', function() {
        $('#showHideComments').toggle(function() {
            $(".commentsSwitch").animate({"marginLeft": "+=53px"}, 500);
            $("#comments").fadeIn(300);
            $("#addComment").fadeIn(300);
        },function(){
            $(".commentsSwitch").animate({"marginLeft": "-=53px"}, 500);
            $("#comments").fadeOut(300);
            $("#addComment").fadeOut(300);
        }).trigger('click');
    });
    

    This will also work :)

提交回复
热议问题