Jump to content

Recommended Posts

Hey Everyone,

 

I thought this would be a simple blur call, but it seems to have some unexpected behavior. So, we have a select box with a blur event, but the blur event fires only if you select an option from the list. Problem, if you click the <select> then click outside the list that pops up (making it dissappear) the select box stays focused...right? right. so, my question is, what's that event?? The event when you click away from the select list without actually blurring the <select>.

 

Any help is appreciated.

 

Thank You,

 

E

Edited by The Letter E
Link to comment
https://forums.phpfreaks.com/topic/273852-jquery-blur/
Share on other sites

There is no such event. Select menus have always been a little unpredictable though, and new JS specs haven't really helped in this particular area. You just have to work around it. This would be pretty simple to implement though.

 

Basically as the select is clicked, attach a new, separate click event to the document that waits for the next click event to bubble up. When that click event is received, check the origin element wasn't the select itself, and if not trigger your blur event.

 

Just be sure to remove the click event from the document when that click is received, or if the normal blur event is triggered. Quick tip by the way! Given you're using jQuery, you can namespace events for easier removal:

 

$(document).on('click.select', function(event) { .. });

 

Then remove it with:

 

$(document).off('click.select');

Link to comment
https://forums.phpfreaks.com/topic/273852-jquery-blur/#findComment-1409406
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.