This input:#chkbox seems weird. Try #chkbox if you only have one element with the identifier #chkbox (and this will be the <input /> field).
In addition, you should probably cache the result of $('#chkbox') , for example:
var $chkbox = $('#chkbox'); $chkbox.click(function() { if ($chkbox.is(":checked")) { $chkbox.next("label").addClass("etykieta_wybrana"); } else { $chkbox.next("label").removeClass("etykieta_wybrana"); } });
You can even use .toggleClass() with switch (second argument, unchecked):
var $chkbox = $('#chkbox'); $chkbox.click(function() { $chkbox.next("label").toggleClass("etykieta_wybrana", $chkbox.is(":checked")); });
Renouncement
No, this does not explain why it worked in Fx, Chrome, etc., and not in IE. I assume that the implementation of the selector is slightly different between browsers. In general, this may not even solve the problem, but only hint at potential problems (and a βcleanerβ solution).
jensgram
source share