In this case, you need prop() , not attr() , replacing the calls with attr() with prop() in your code will work.
From http://blog.jquery.com/2011/05/10/jquery-1-6-1-rc-1-released/
The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took property values ββinto account when retrieving certain attributes, which can lead to inconsistent behavior. Starting with jQuery 1.6 , the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.
elem.checked ==== true (Boolean) The status of the flag will be changed
$(elem).prop("checked") ==== true (Boolean) Will be changed with the state of the checkbox
elem.getAttribute("checked") ===== "checked" (String) The initial state of the flag; does not change
$(elem).attr("checked") (1.6) ===== "checked" (String) The initial state of the flag; does not change
$(elem).attr("checked") (1.6.1+) ======== "checked" (String) The status of the flag will be changed
$(elem).attr("checked") (pre-1.6) ======= true (Boolean) Changed with checkbox state
Also this url will help you to know more about your requests .prop () vs .attr ()
Difference /is-checked-vs-attr-checked-checked/7 at http://jsperf.com/is-checked-vs-attr-checked-checked/7
Also, for an understanding of The elements atttribute and properties see http://christierney.com/2011/05/06/understanding-jquery-1-6s-dom-attribute-and-properties/ http://jsperf.com/is-checked -vs-attr-checked-checked / 7
Rohan kumar
source share