Reputation: 28843
Take a look at the following code:
$(document).ready(function()
{
$('#link').click(function()
{
alert('1');
},
function()
{
alert('2');
});
});
Alert 2 will never happen! However I'm wanting to make a link do something different on it's next click so like it's an off and on switch. How do I do this in jQuery?
Upvotes: 1
Views: 660
Reputation: 3686
$().toggle()
does this.
pass as many functions as you like, and it will execute them in order.
$("#link").toggle(
function() {
alert("1")
},
function() {
alert("2")
}
);
hope that helps! cheers.
Upvotes: 1
Reputation: 30135
$('#link').toggle(function(){
alert('1');
},function(){
alert('2');
});
Upvotes: 4
Reputation: 11567
$(document).ready(function()
$('#link').toggle(function() {
alert('1');
}, function() {
alert('2');
});
});
Upvotes: 1