tags:

views:

27

answers:

2

I've just started reading a book on jQuery and was just messing around with animations. If I have a <div> nested in another <div>, how do I stop the nested <div>'s animation from affecting it's parent?

<script type="text/javascript">
      $(document).ready(function(){

            $("#outerDiv").click(function () {
                $("#outerDiv").slideUp("slow");
            });

            $("#innerDiv").click(function () {
                $("#innerDiv").slideUp("fast");
                //event.stopPropogation(); thought this would work, guess not
            });

            $("p").click(function () {
                $("div").slideDown("slow");
            });
      });
+1  A: 

Inorder to use the event object you need to add it as a param in your function:

$("#innerDiv").click(function (event) {
    $("#innerDiv").slideUp("fast");
    event.stopPropagation();
});
PetersenDidIt
Doesn't seem to make a difference. It still makes the outer div slide up when the inner div is clicked
Justen
This answer is correct, just copied over the mis-spelling. No need for a down-vote.
patrick dw
I never down-voted you just so you know.
Justen
+5  A: 

You have propagation spelled incorrectly.

Yours is stopPropogation

patrick dw
that is valid point +1
c0mrade
oh geez. Thanks, but let's pretend this didn't happen >.>
Justen
good eyes .. +1
Gaby
+1 for making me lol!
Reigel