Remove focus on the select item when changing, or if not changing using jquery

I have the following code that removes the focus of the selection menu when the selected item changes:

$("select").change( function() { $(this).blur(); }); 

However, if I do not select another option for the one that has already been selected, the blur () function will not start ... because nothing has changed.

Is there a β€œchange or not change” function?

+4
source share
1 answer

Try

 var c = 0; $("select").bind('click', function() { event.stopPropagation(); if (c++ % 2 == 1) { console.log(c); $(this).blur(); } }); $('html').click(function() { if ($('select').is(':focus')) c = 1; else c = 0; });​ 

jsfiddle.net/5eE8x

Update.

+1
source

All Articles