Gary Stewart
Gary Stewart

Reputation: 31

Jquery - Muliple clicks causing issues

The issue I face is that when I click on #apple1 multiple times, the accordion panel i.e. appleInfo1 moves up and down repeatedly until it has matched up with how many times I have initially clicked the button.

$('#appleInfo1').hide().promise().done(function(){
    $('#apple1').click(function(){
        $('#appleInfo1').slideToggle(1000);
        $('#intelInfo1, #ibmInfo1, #amdInfo1').slideUp(1000);
    });
});

Upvotes: 0

Views: 42

Answers (1)

adeneo
adeneo

Reputation: 318212

You need to stop() any ongoing animations when you click again.
Also, the promise makes little sense when not passing in a duration to hide()

var apple = $('#appleInfo1').hide()

$('#apple1').click(function(){
    apple.stop(true,true).slideToggle(1000);
    $('#intelInfo1, #ibmInfo1, #amdInfo1').stop(true,true).slideUp(1000);
});

Upvotes: 1

Related Questions