I have a login box that slides/toggles up and down when an <a>
link is clicked.
This is a DIV that is around 150px by 100px is size.
When someone clicks outside this DIV I want the DIV to slide backup. I've been playing with focusout() but I must have the wrong function.
Any advice? code below.
$('a开发者_高级运维#member_login').click(function(event) {
event.preventDefault();
$('div#member_login_container').slideToggle();
});
// Hide Login Box if Click outside the Login Box
$('div#member_login_container').focusout(function(event) {
alert('here');
//$('div#member_login_container').slideUp();
});
You should check out blur
http://api.jquery.com/blur/
example: http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_event_focus_blur
A better version:
$("input.login_input").focus(function () {
$(this).addClass("active");
$(this).focusout(function () {
$(this).removeClass("active");
});
});
精彩评论