0

Can anyone give me a solution to this problem on IE8. I have this: HTML:

 <label>
        <input type="checkbox" checked /><i class="icon-fixed-width icon-check"></i> Three
    </label>

CSS:

[type=checkbox] { display: none; }
label { cursor: pointer; }
[class*=icon-].icon-fixed-width { text-align: left; }

jQuery:

$("[type=checkbox]").change(function () {
    $checkbox = $(this)
    $icon = $checkbox.siblings("[class*=icon-]")

    checked = $checkbox.is(":checked")

    $icon.toggleClass('icon-check', checked)
        .toggleClass('icon-check-empty', !checked)
});

All work fine on modern browsers but on IE8 wont work. What is wrong here? Fiddle:

ty.

1 Answer 1

1

Just add a semicolon after each Javascript line. I think the IE8 Javascript engine "crashes" when you do not end your Javascript statement with ;

$("[type=checkbox]").change(function () {
    $checkbox = $(this);
    $icon = $checkbox.siblings("[class*=icon-]");
    checked = $checkbox.is(":checked");
    $icon.toggleClass('icon-check', checked).toggleClass('icon-check-empty', !checked);
});

Fiddle

5
  • @Mark Bell nope, is not working :( What is strange, if I remove display:none; from css and in page are rendered 2 checkboxes(the default one and the other from icon-awesome) is working ... Feb 4, 2014 at 12:31
  • Is my fiddle example not working on your IE8 ? If you tried to change directly your javascript code, are you sure cache have correctly cleaned ? I already had troubles with javascript cache and IE8.
    – franchez
    Feb 4, 2014 at 12:34
  • @RulerNature This is not my answer; all I did was edit it slightly to improve the formatting...
    – Mark Bell
    Feb 4, 2014 at 12:35
  • @franchez yes I'm sure :| I think IE8 has problems with that .change on hidden elements . Feb 4, 2014 at 12:47
  • @RulerNature I did additional tests and indeed not working. Maybe it would be simpler to apply your custom icon directly on the checkbox, what do you think ?
    – franchez
    Feb 5, 2014 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.