Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery toggle running twice

It seems that this code:

$(function(){
    $('.show_hide_login').toggle(
    function (){
            alert('show');
            $("div#fullpage").show();
            $("div#loginbox").show();
        },
  function (){
            alert('hide');
            $("div#loginbox").hide();
            $("div#fullpage").hide();
        }
  ); });

Any idea on why it would be running twice when I click on either link (two, one is a div and one is an anchor)?

like image 252
Nathan Avatar asked Sep 09 '10 23:09

Nathan


1 Answers

How many elements do you have with the .show_hide_login class? I'll guess you have two of those. In which case, $('.show_hide_login') result contains two elements, and toggle() is executed for each of them.

like image 111
Franci Penov Avatar answered Nov 13 '22 22:11

Franci Penov