Problem
I'm trying to toggle between two functions when a button is clicked using jQuery's .toggle() method, but the button itself goes away as soon as the DOM is ready.
Code
$(document).ready(function() {
$("#panel").css({"height": "0%", "bottom": "0"});
/*
var already_clicked = false;
$("button").on("click", function() {
if (already_clicked) {
$("#panel").animate({"height": "0%"}, 500);
already_clicked = false;
} else {
$("#panel").animate({"height": "100%"}, 500);
already_clicked = true;
}
});
*/
$("button").toggle(function() {
$("#panel").animate({"height": "100%"}, 500);
}, function() {
$("#panel").animate({"height": "0%"}, 500);
});
});
Markup
<body>
<div id="panel"></div>
<button>Click me</button>
</body>
Note: The solution in the comment block works as intended, but I'm not sure why .toggle() doesn't works.