jquery attr('checked','checked') works only once jquery attr('checked','checked') works only once jquery jquery

jquery attr('checked','checked') works only once


Use prop('checked', true / false) instead of removeAttr

$('input[name=foo]').prop('checked', true);$('input[name=foo]').prop('checked', false);


You can change the attribute, and that will also change the property, if the element is untouched. Once the element leaves this initial state, changing the attribute no longer affects the property. The exact behavior probably varies between browsers.

Instead of .attr('checked', 'cheked') use .prop('checked', true)