scorpio1441
scorpio1441

Reputation: 3088

jQuery: lose focus on the element

Need to somehow lose focus on <select> after the <option> has been selected.

http://jsfiddle.net/MnAdN/

Without removing this focus check.

if (... !$('#adm1n-toolbar form select').is(':focus'))

Toolbar should be visible while user is doing selection, and should be hidden when selection is done.

Thanks.

Upvotes: 11

Views: 15924

Answers (3)

Sam Tyson
Sam Tyson

Reputation: 4616

Just force the focus off the toolbar:

$('#adm1n-toolbar select').trigger('blur');

Using your jsFiddle:

$('#adm1n-toolbar')
    .mouseenter(function() {
        var toolbarposition = $(this).position();
        if (toolbarposition.top < 0) {
            $(this).animate({top: '0'}, 300);
        }
    })
    .mouseleave(function() {
        var toolbarposition = $(this).position();
        if (toolbarposition.top >= 0 && !$('#adm1n-toolbar form select').is(':focus')) {
            $(this).animate({top: '-115'}, 300);
        }
    });

$('#adm1n-toolbar select').change(function(e) {
    e.preventDefault();
    $(this).trigger('blur');
});

Upvotes: 2

DA.
DA.

Reputation: 40673

Trigger a blur event:

$('#yourSelect').blur();

Upvotes: 5

Elliot Bonneville
Elliot Bonneville

Reputation: 53301

You can use the blur() method, like this:

$("#adm1n-toolbar form select").change(function() {
    $(this).blur();
}); // after something has been selected

Upvotes: 18

Related Questions