Reputation: 109
Trying to do a function that does "A" when toggle open and "B" when toggle close.
Code:
function awesome_toggle()
{
$(".button").click(function()
{
$("content").toggle(
function()
{
/* Do "A" */
},
function()
{
/* Do "B" */
}
);
});
}
This code doesn't seem to work and I can't figure out why. When I use only one function, so I stop the code after /* Do "A" */ it works but when I add the /* Do "B" */ function it stops working. What is wrong?
jquery version: ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
Upvotes: 1
Views: 4137
Reputation: 15714
As the comments have said, this version of toggle
has been deprecated.
There may very well be a better way to accomplish what you want, but you can check whether the element is visible after toggle with the :visible
selector, and do stuff conditionally based upon that.
function awesome_toggle()
{
$(".button").click(function() {
$("content").toggle(normalSpeed, function () {
if ($("content").is(':visible')) {
/* Do "A" */
} else {
/* Do "B" */
}
});
});
}
Upvotes: 6