Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should be setting your field itself to have the <code>.focus()</code> listener, rather than the wrapping <code>&lt;form&gt;</code>.</p> <pre><code>$('#new_wall').focus( function(){ $("#send_button").fadeIn(400); }); $('#new_wall').blur( function(){ $("#send_button").fadeOut(400); }); </code></pre> <p>Blur should work on the field. You can't "unfocus" from something that can't have focus (like an <code>&lt;a&gt;</code> or <code>&lt;input&gt;</code>).</p> <p>Example: <a href="http://jsfiddle.net/7p77p/" rel="nofollow">http://jsfiddle.net/7p77p/</a></p> <p>I don't know what you're trying to do with your field when someone "clicks" on the form (not a solid interaction with the form), so I'm going to ignore that for now. Your field should carry the focus and blur events, however, and your button should respond in kind.</p> <p><strong>Edit:</strong> Based on silly oversight on my part.</p> <p>Then the way I would handle it is this:</p> <pre><code>$('#new_wall').focus( function(){ $("#send_button").fadeIn(400); // Button shows on focus // Create a temporary listener on the body to let someone 'click off' $('body').on('click.send_button_showing', function(){ // User clicks off, button fades out, loses event, and body loses event $('#send_button').fadeOut(400); $('#send_button').off('click.send_button_click'); $('body').off('click.send_button_showing'); }); // Create temporary event that stops bubbling of the body click // with .stopPropagation() $('#send_button').on( 'click.send_button_click', function(e){ e.stopPropagation(); // Do your send button actions }); }); </code></pre>
 

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