Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery lose focus event

People also ask

Which event is used to lose its focus in jQuery?

jQuery focusout() MethodThe focusout event occurs when an element (or any elements inside it) loses focus. The focusout() method attaches a function to run when a focusout event occurs on the element, or any elements inside it.

What is the difference between jQuery Focusout () and Blur () events?

The focusout event fires when an element is about to lose focus. The main difference between this event and blur is that focusout bubbles while blur does not.

Which event is triggered when a field loses focus?

The onblur event occurs when an object loses focus. The onblur event is most often used with form validation code (e.g. when the user leaves a form field).

How do you know if an element loses focus?

The onfocusout event occurs when an element is about to lose focus. Tip: The onfocusout event is similar to the onblur event. The main difference is that the onblur event does not bubble. Therefore, if you want to find out whether an element or its child loses focus, you should use the onfocusout event.


Use blur event to call your function when element loses focus :

$('#filter').blur(function() {
  $('#options').hide();
});

Like this:

$(selector).focusout(function () {
    //Your Code
});

Use "blur": http://docs.jquery.com/Events/blur#fn


blur event: when the element loses focus.

focusout event: when the element, or any element inside of it, loses focus.

As there is nothing inside the filter element, both blur and focusout will work in this case.

$(function() {
  $('#filter').blur(function() {
    $('#options').hide();
  });
})

jsfiddle with blur: http://jsfiddle.net/yznhb8pc/

$(function() {
  $('#filter').focusout(function() {
    $('#options').hide();
  });
})

jsfiddle with focusout: http://jsfiddle.net/yznhb8pc/1/