javascript - Closing form on "blur" -- Is there a better way? -


so, i'm trying close form on blur, e.g. facebook comments. issue is, had a:

$(window).click(function(){ $('.comment_form').hide(); }); $('.comment_form').click(function(){ return false; }); 

which worked fine, however, adding return false, cancels out submit button when clicked when went make live.

i thought work logically instead:

$('*:not(.comment_form,.comment_form *)').click(function(eve) {     $('.comment_form').hide(); }); 

but, unfortunatly, doesn't , assume it's because when click on, let's say, .comment_form clicking on body, div, div... etc hides multiple times.

my work around finally

$('*').click(function(eve) {     if(!$(eve.target).is('.comment_form,.comment_form *'))     {         $('.comment_form').hide();     } }); 

however, i'm not sure , why im asking. going fire click event every single click.

does have suggestions?

your solution on right track, might saner attach event document, instead of all elements (*):

$(document).click(function(eve) {     if (!$(eve.target).is('.comment_form, .comment_form *')) {         $('.comment_form').hide();     } }); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -