Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox/Internet explorer behavior with selecting/highlighting an item in the select tag

I've noticed that in firefox, when you click on the arrow to open a 'select' tag of the dropdown, and then point at one option, the row is highlighted in blue color background as I expect, that is OK.

But in Internet Explorer, when you click on the option you want to select and it becomes the selected option, the blue highlighting remains until you click somewhere else outside the select tag.

Is there any way to change that behavior?

like image 811
user1966221 Avatar asked Feb 27 '13 11:02

user1966221


2 Answers

One way would be to use JavaScript. I've used jQuery to make it easier: JSFiddle example.

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

This removes focus from the element when an option has been selected.

To do this pure JavaScript you'd use onchange.

like image 53
James Donnelly Avatar answered Nov 17 '22 10:11

James Donnelly


I had this issue and used James Donnelly's solution but also wanted to prevent the highlight remaining if the current option is selected (try James' jsfiddle in IE or see wilsonrufus's comment).

Putting a click handler on the options seems to get around that:

var select = $('select');

select.change(function() {
    select.blur();
})

$('select option').click(function() {
    select.blur();
})
like image 20
Tom Elmore Avatar answered Nov 17 '22 08:11

Tom Elmore