mrpatg
mrpatg

Reputation: 10117

toggling jquery animation getting error

Im trying to have a layer animate/expand hight on click of a "show" button, and then, within the layer, have a button to hide it back to 0.

    $(".showcart").click(
        function(){ $("#cart").animate({ height: "400px" }); $(".showcart").toggle();});
            $(".hidecart").click(function(){
            $("#cart").animate({height: "0px"});
        }); 

});

Not sure where the problem is, any ideas?

Upvotes: 0

Views: 76

Answers (2)

Mickel
Mickel

Reputation: 6696

Try wrapping your code inside the DOM ready event...

$(function() {
    $(".showcart").click(function(){
        $("#cart").animate({ height: "400px" });
        $(".showcart").toggle();
    });
    $(".hidecart").click(function(){
        $("#cart").animate({height: "0px"});
    });
});

Upvotes: 1

marcgg
marcgg

Reputation: 66436

$(".showcart").click(function(){ 
       $("#cart").animate({ height: "400px" }); 
       $(".showcart").toggle();});
       $(".hidecart").click(function(){
                  $("#cart").animate({height: "0px"});
       });
});

Upvotes: 1

Related Questions