Why does jQuery don’t return value of ‘checked’ attribute?
It always returns ‘checked’, no matter what is in it.
<div id='div' checked='checked_value'></div>
<script>
var attr_value = $('#div').attr('checked');
alert(attr_value);
// attr_value == 'checked' no matter what
</script>
It was okay, in 1.4, but when I upgraded to 1.8 it totally messed my code. I use checked attribute a lot.
I believe in the more recent versions of jQuery the correct syntax would be –
prop()I believe however, that you might be using this property incorrectly. Usually, one would just test for the existence of the
checkedselector. There can really only be two states. Checked and unchecked. Usually, one would use something like this –This would return a list of all the matched checkboxes that are checked. You also used this property on a
<div>element. This is not valid HTML. You should really stick to valid markup if you want the most consistent results across browsers.