Reputation: 12998
I have the following code which removes the focus of a select menu when the selected item is changed:
$("select").change( function() {
$(this).blur();
});
However, if I do not select a different option to the one that was already selected, the blur() function does not run... because nothing has changed.
Is there a "change or not changed" function??
Upvotes: 4
Views: 7214
Reputation: 2768
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;
});
Updated.
Upvotes: 1