Tania Marinova
Tania Marinova

Reputation: 1898

is there any way to remove the focus on select in this case

In IE when you choose an option and and it becomes the selected option the blue highlighting remains until you click somewhere else outside the select tag. (In firefox it's not that way)

SO I wrote a script removes focus from the element when there is a change event on the select .

But still one little problem stays: if i choose Hello and then again Hello option - the focus will remain and the blue highlighting. But if I choose hello and then world option -everything works.. so you see the script when you click on an option to remove the focus.

Then I saw that the user can just press enter without clicking the option -so I wrote the enter case

But as soon as i got happy i found a problem. there is one last case (i pray it's the last) which is almost the same as the previous - you click on the select and of course you see all the options and you see that the highlighted option in blue is what you want ) - but this time you decide not to press enter to select that option, but just to click again on the select tag -so in this case there is no click event on the option, no pressing of enter and no change event and the highlightening stays – Is there any way to fix that

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

$('#select option').click(function(event) {
    $('#select').blur();
});

$('#select').keydown(function(event) {
    // Enter pressed
    if(event.keyCode == 13) {
        $('#select').blur();
    }
});

Upvotes: 1

Views: 1691

Answers (1)

1Mayur
1Mayur

Reputation: 3485

although it is bad practice but try this

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

Upvotes: 1

Related Questions