Trigger second function in toggle()
I开发者_JS百科s there a way I can call the second function in toggle(function(){},function(){})
You could skip the toggle to the next function, if you really wanted to I suppose, for example:
$("div").toggle(function() {
alert("First");
}, function() {
alert("Second");
});
Then you can manually advance the .toggle()
function array (without calling the first function), like this:
$("div").data('lastToggle' + $("div").data().events.click[0].handler.guid, 1);
Then just click the element or $("div").click()
, etc, and it'll fire the second function.
You can give it a try here, note that this only works in jQuery 1.4+ and is really just to show it's possible. You should however either bind them in reverse order, or give the second argument a named function as the other answers suggest.
how about
toggle(function(){ callFunctionOne(); callFunctionTwo(); });
I suggest such solution:
toggle(function(){},secondFunction);
function secondFunction() {}
And now you can call it how you want :)
精彩评论