Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

toggle function

Tags:

jquery

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();
  });
like image 977
Mihir Avatar asked Sep 01 '26 20:09

Mihir


1 Answers

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()`.
like image 88
Frédéric Hamidi Avatar answered Sep 04 '26 09:09

Frédéric Hamidi