intargc
intargc

Reputation: 3121

jQuery .is(':checked') always returns false

No mater if the radio button is checked or not, .is(':checked') will return false. Here is some stuff I was playing with in Chrome's console while I was debugging this:

> $('#blah')
[<input type=​"radio" id=​"blah" name=​"blah_type" value=​"blah" class=​"styled" checked=​"checked">​]
> $('#blah').removeAttr('checked')
[<input type=​"radio" id=​"blah" name=​"blah_type" value=​"blah" class=​"styled">​]
> $('#blah').is(':checked')
false
> $('#blah').prop('checked', true)
[<input type=​"radio" id=​"blah" name=​"blah_type" value=​"blah" class=​"styled">​]
> $('#blah').is(':checked')
false
> $('#blah').prop('checked')
true
> $('#blah').removeProp('checked')
[<input type=​"radio" id=​"blah" name=​"blah_type" value=​"blah" class=​"styled">​]
> $('#blah').attr('checked', true)
[<input type=​"radio" id=​"blah" name=​"blah_type" value=​"blah" class=​"styled" checked=​"checked">​]
> $('#blah').attr('checked')
"checked"
> $('#blah').prop('checked')
undefined
> $('#blah').is(':checked')
false

What could be going wrong here? I'm using jQuery 1.6.4.

Upvotes: 4

Views: 7506

Answers (2)

Rup Majumder
Rup Majumder

Reputation: 241

use .prop('checked').

I too faced the same problem. .is() is not able to catch the checked status for a check box element.

Upvotes: 5

Phil
Phil

Reputation: 1308

According to the jQuery API docs, do not use .removeProp() to remove checked or other native properties. I would assume the same for .removeAttr() as well.

http://api.jquery.com/removeProp/

Upvotes: 1

Related Questions