I have a simple script that on <a> click it checks or unchecks a checkbox. All works fine the first time, but once the value is altered with jQuery it’s not being updated (though in Chrome’s inspector the attribute checked="checked" is being added/removed).
HTML:
<a href="#" class="js-tick-untick-checkbox">
<input type="checkbox" class="send-invite-checkbox" />
Something something in the month of May
</a>
jQuery:
$('.js-tick-untick-checkbox').click(function() {
var checkbox = $(this).find('.send-invite-checkbox');
if ($(checkbox).attr('checked') === 'checked') {
checkbox.removeAttr('checked');
$(this).removeClass('selected-element');
} else {
checkbox.attr('checked', 'checked');
$(this).addClass('selected-element');
}
return false;
})
Check out the demo: http://jsfiddle.net/y3e0jfc6/
I tried various other options, like checked="true" / checked="false", none work…
Any ideas? Thanks.