2

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();
});
marcgg
  • 62,686
  • 49
  • 174
  • 225
Adam
  • 18,593
  • 35
  • 115
  • 195
  • Have a look at this: http://stackoverflow.com/questions/1403615/use-jquery-to-hide-div-when-click-outside-it – Behrang Sep 05 '11 at 09:59

2 Answers2

3

You should check out blur

http://api.jquery.com/blur/

example: http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_event_focus_blur

JSantos
  • 1,684
  • 21
  • 39
1

A better version:

$("input.login_input").focus(function () {
    $(this).addClass("active");
    $(this).focusout(function () {
        $(this).removeClass("active");
    });
});
Sliq
  • 14,811
  • 24
  • 103
  • 139