Reputation: 8734
my question is two functions are passed to toggle why.. and out side another function is there that is also confusing plz tell me
$('#login a').toggle(function() {
$(this)
.addClass('active')
.next('form')
.animate({'height':'show'}, {
duration:'slow',
easing: 'easeOutBounce'
});
}, function() {
$(this)
.removeClass('active')
.next('form')
.slideUp();
});
$('#login form :submit').click(function() {
$(this)
.parent()
.prev('a')
.click();
});
Upvotes: 3
Views: 261
Reputation: 21
According to JQuery API documentation functions will be called on alternating clicks:
As for handler of submit button, it simulates click for anchor (a) element that is sibling to element that contains the button and is located before container element. Like this:
<a href="#">click will be simulated for this link</a>
<div>
<input type="submit"/>
</div>
Upvotes: 0
Reputation: 263117
The toggle() method takes two (or more) functions as arguments and calls one of them alternately each time the element is clicked.
Functions are first class citizens in Javascript: you can manipulate them like any other object, including passing them to other functions:
function foo(otherfunction)
{
otherfunction();
}
function bar()
{
window.alert("bar() was called.");
}
foo(bar); // Ultimately calls `bar()`.
Upvotes: 1