I thought this would work:
if ($(this).attr('checked')) {}
but I had to write it this way:
if ($(this).is(':checked')) {}
Q: Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Having been through this recently, it depends on what version of jQuery you are using. As of 1.6, the functioning of
attrwith native properties (e.g. “checked”, “disabled”) — properties being attributes that are supposed to either exist or not – changed, because they could return inconsistent results depending on browser behavior.The correct way to set or test a property in 1.6 is with the new
propfunction, which returns true or false always. The 2nd method you use is also valid to test.