replace
$(".my-label").click
with
$(".my-label").click();
You're not calling the method with click
. You're just referencing it. I wonder why it works in Safari/Chrome: it shouldn't.
Edit: user edited the question, providing more context.
Most likely, the reason why it is not working now is because you're missing a document ready. Replace your code with:
$(document).ready(function(){
console.log("document ready!");
$(".my-label").click(function(){
console.log("click function!");
});
});
Please report back with what you see in your JavaScript console.
If now it is working, the reason why Safari/Chrome were already ok is because, in those browser, the code was executed after the DOM rendering. That was just luck. Never you should rely on the DOM being ready: always put all of the code referencing any DOM node inside of a $(document).ready()
call.
If this is still not working in IE11, then you should provide more context to your question. For example, what does console.log($(".my-label").length)
returns? If it is 0
, then IE11 is not finding the node. Again, the only reason why this should happen is because the DOM is not ready or, perhaps, the code itself doesn't get called. If you have any error before $(".my-label").click()
that code won't get executed. Please note that many "errors" that are accepted in normal browser are not in IE. If you don't post what you see in IE11 JavaScript console, I assume it is clear (and thus there are no errors) but I don't know if you even checked that so I'm taking this as a possibility.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…