8
I’m using this script in Chrome and it works normally. But in IE 8 or 9 it doesn’t work. I put a Debugger and an Alert to debug, but it doesn’t even enter the function.
$(document).on("mousedown", '#CentroCusto_new option', function (event) {
alert('oi');
this.selected = !this.selected;
event.preventDefault();
});
Someone knows the reason and how to fix?
Tried to simply return
false
instead of setting returnValue? jQuery normalizes that.– bfavaretto
Another thing: you need to be with the IE dev tools open, or the first line (
debugger
) is gonna suck.– bfavaretto
Does the rest of the program work normally? (the part that depends on jQuery, mainly) Is there any other working code that uses
on
? And a long shot: ever tried to put your Handler in thebody
or some other ancestral element of#CentroCusto_new
, instead of thedocument
?– mgibsonbr
In IE it cannot even enter the function, nothing inside will work. @bfavaretto
– Joao Paulo
Now I noticed that you are trying to get clicks on options. Why not monitor the select change instead?
– bfavaretto
It didn’t work on the body. I put it in the option because I am preventing his default behavior that is to deselect others by clicking on one.
– Joao Paulo
I think the ie is not accepting the selector
– Joao Paulo
I know it sounds crazy, but try putting an attribute
size
with numerical value in its select. See http://stackoverflow.com/a/3341779/825789– bfavaretto
It didn’t work. I’m here without knowing what else to try.
– Joao Paulo
I created a Jsfiddle. http://jsfiddle.net/fp4WD/
– Joao Paulo
I’m on Linux right now, but as I recall, IE doesn’t trigger the
click
inoption
but rather in theselect
. Try attaching the event toclick
to yourselect
and collects the value ofoption
: Jsfiddle Aqui– Zuul
I tested on IE8 and IE9, there is no way you can capture the event by clicking on an option, but you can capture in select, the event will not tell you who is selected, but you can find out in the properties of the element.
– Gabriel Gartz
regarding your Jsfiddle, I see that IE has problems with the version of jQuery 1.10.1, see the error it gives on the console:
SCRIPT5: Acesso negado.
jquery-1.10.1.js, linha 1513 Caractere 2
SCRIPT5009: '$' não está definido 
_display, linha 21 Caractere 5

– Paulo Roberto Rosa
believe it or not, the order Voce calls the scripts in your html interfere in whether or not the IE’s work, something else, each function needs a separate file because if not the IE gets lost, discovered this when I had a Jquery function file of over 100 lines and IE didn’t even read the file...
– RodrigoBorth
I saw this problem in stackoverflow in English, can you adapt my code with the accepted answer code? I tried but I don’t think so, because I need the default option Prevent. http://stackoverflow.com/questions/3341740/click-event-for-option-doesnt-work-in-ie
– Joao Paulo
I was able to solve this problem? Looking quickly at the idea that occurs to me is: http://jsfiddle.net/k4G3J/
– Sergio