Psytronic
Psytronic

Reputation: 6113

Jquery event for select tag closing

I can hook into the change event of the select fine (Which will cause the select to close), which is not a problem. But I also need to detect when the select tag is closed by way of clicking on the screen elsewhere.

So far everything I've tried hasn't worked; body click, body focus, select blur, select focusout are among the few combinations.

With most of them it will only register on the second click on the body, so: Click1) Select closes, event doesn't fire. Click2) Event fires.

I know I could create my own version of a select tag (And have done so before), but it seems a bit overkill for this situation when the normal select is fine, I just need this one event.

Cheer, Psy

Upvotes: 3

Views: 4674

Answers (1)

FiLeVeR10
FiLeVeR10

Reputation: 2265

Sounds like a blur thang...

$('select').on('change', function() {
    //change things here 
}).on('blur', function() {
    //when select is no longer in focus here
});

Made a fiddle

Upvotes: 1

Related Questions