cannot check a checkbox input via jquery in ie9

Go To StackoverFlow.com

4

I have no idea why this wont work but I have tried the following:

$('#elemid').prop('checked', true);
$('#elemid').attr('checked', true);
$('#elemid').attr('checked', 'checked');

IE9 just absolutely refuses to actually check the box when the code is run. I know the code is being run due to console.log.

However no checked element.

This code works perfectly in FF and Chrome. Am I missing something here?

2012-04-04 06:27
by SublymeRick
It works, tested in ie9, http://jsfiddle.net/5Yycf - xdazz 2012-04-04 06:32
My guess is you have forgotten to run the code on documentReady using the $(function() { ... }); construction - Interrobang 2012-04-04 06:34
.prop() is included in jquery version 1.6, Make sure you have the right version., and this will be support by IE9 , hope you might have done a small mistake around. the browser prior to IE9 will have memory leaks in using prop() hope you didn't forgot about it - iDroid 2012-04-04 06:41
My sample code above is not the same as the actual code. And its within a scope of a large app so reposting the exact code here wont work. I'm ripping my hair out over this. -- The code has nothing to with doc ready. Its a toggle function that gets executed when a link is clicked - SublymeRick 2012-04-04 06:42
I'm using latest jquery - SublymeRick 2012-04-04 06:43
Somethings totally f**ked here... even using straight non-jquery javascript it doesnt work.. - SublymeRick 2012-04-04 06:45
What does the Javascript console tell you? Did you try to debug step by step? All major browsers support setting breakpoints and use F10 and F11 to step through your code and watch variables/object - devnull69 2012-04-04 06:53


1

Ok, my problem was incredibly stupid.....

I had each checkbox inside a floated labels. why I used labels for this is beyond me, but the label was also registereing a click which was unchecking the box immediately after my code "checked" the box.

I was able to fix the issue by moving the input's out side of the label fields (they are display: none anyway)

The whole point of this is a fancy checkbox system with logos instead of check boxes. The background of the label changes when its click to show active selection etc etc.

Thanks for the help guys.

2012-04-04 06:53
by SublymeRick
Ads