Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Toggle saves it's state on the object you call it on. Each time you call Toggle, it alternates between function 1 and function 2. It knows nothing else about your app. It just alternates between the two functions you pass it each time you call it.</p> <p>When you reset the state of the popup without using Toggle, it gets out of sync as it now has no idea that you want to go back to the first state. So, when you click again, it executes the second function when you want it to execute the first function.</p> <p>The best way to solve this problem is to use something smarter than Toggle. You need to either detect whether the popup is open and act accordingly or store some state on whether it's open or not. You can't use Toggle because it isn't smart enough for your application.</p> <p>In working with your actual code, I also found that handling the mouseup event in the document is not very compatible with handling the click event in the object. The issue is that mouseup comes before click so you would get both events in sequence and you wouldn't get the effect you want. When I changed to a click in the document, it worked a lot easier like this:</p> <pre><code>$("#general_show").click(function () { var $this = $(this); if ($this.hasClass('selected')) { $this.removeClass('selected').parent().next().hide(); } else { $this.addClass('selected').parent().next().show(); } return(false); }); $(document).click(function (e) { if ($('#general_info').is(':visible') &amp;&amp; $(e.target).parents('#general_info').length === 0) { $('#general_show').removeClass('selected').parent().next().hide(); return(false); } }); </code></pre> <p>Working example: <a href="http://jsfiddle.net/jfriend00/KTNAq/" rel="nofollow">http://jsfiddle.net/jfriend00/KTNAq/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload