test whether button being clicked before running function on element.blur()
<p>I have a function called showHide() that alternately shows and hides a text input field and a button (button2) when another button (button1) is clicked. The text input field is automatically focused when it opens, and this works great.</p>

<p>The HTML looks roughly thus:</p>

<pre><code>&lt;button1&gt;Show/Hide&lt;/button&gt;
&lt;form&gt;
  &lt;input class="hidden" type="text" /&gt;
  &lt;button2 type="submit"&gt;Submit&lt;/button&gt;
&lt;/form&gt;

&lt;script type="text/javascript"&gt;
  $("button1.someSelectors").click(function() {showHide();});
  $("input.someSelectors").blur(function() {showHide();})
&lt;/script&gt;
</code></pre>

<p>I would like to extend the function such that when the input field loses focus it and button1 disappear, <em>unless</em> it loses focus because button1 is being clicked. As it reads now I'm only testing whether the input field has focus or not. How can I also check whether button2 is being clicked or not?</p>

<p>I tried:</p>

<pre><code>$("input.someSelectors").blur(function() {
  if (!$("button2.someSelectors").is(":focus")) {
    showHide();
  }
});
</code></pre>

<p>but it hid the form elements even when I tried clicking button2.</p>

<p>An alternative would be to test whether button2 is being clicked or not in the "hide" part of the function, but when I added</p>

<pre><code>if(!$("button2.someSelectors").click()) {do the hide part of the function}
</code></pre>

<p>to showHide(), the form got submitted when I clicked button1 <em>or</em> button2. Here is an <a href="http://claymanmatthews.com/registry/example.php" rel="nofollow">example</a> of my problem. Can anyone help?</p>

<p>--<em>Edit:</em></p>

<pre><code>var showHide=function(item, category) {
  if($("input."+item+"."+category).hasClass("hidden")) {
    $("input."+item+"."+category).show("fast").focus().removeClass("hidden");
    $("button.buy."+item+"."+category).show("fast");
    $("button.purchase."+item+"."+category).text("Never mind!");
  } else {
    $("input."+item).hide("fast").addClass("hidden");
    $("button.buy."+item).hide("fast");
    $("button.purchase."+item).text("Purchase");
  }
}
</code></pre>
