eric2872
eric2872

Reputation: 122

jQuery .animate keeps triggering without a click

This code is supposed to wait until the user clicks on something other than div id="s" and then returns to its place but it keeps triggering immediately when I click. I want it to stay open!

Here is the code and jsfiddle: http://jsfiddle.net/hBb9L/

 $("#e").click(function() {
  //done
$("#re").animate({
  "margin-top": "104px"
}, 800);
$("#ret").animate({
  "margin-top": "104px"
}, 800);
$(".popu").animate({
     "margin-top": "-102px"
 }, 800);
 $("#s").show(200);

$("div:not(#s)").click(function() {
$("#re").animate({
  "margin-top": "0px"
}, 800);
$("#ret").animate({
  "margin-top": "0px"
}, 800);
$(".popu").animate({
     "margin-top": "0px"
 }, 800);
 $("#s").hide(200);
 });



 });

Upvotes: 0

Views: 50

Answers (1)

kei
kei

Reputation: 20491

Your need .stopPropagation()

DEMO

$("#e").click(function (e) {
        //done
        $("#re").animate({
            "margin-top": "104px"
        }, 800);
        $("#ret").animate({
            "margin-top": "104px"
        }, 800);
        $(".popu").animate({
            "margin-top": "-102px"
        }, 800);
        $("#s").show(200);
        e.stopPropagation();
});

Upvotes: 1

Related Questions