I have the below JQuery code on a Rails 5 app. Works fine if I check the box the first time. Also works fine if I uncheck the same checkbox. But when I reclick the same box I initially clicked, it no longer checks off the box. Anything I'm missing in my code below?
$(".filter-wrapper-f").click(function(){
var $checkbox = $(this).children(".checkpic");
if ($checkbox.attr('checked')){
$checkbox.removeAttr('checked');
} else {
$checkbox.attr('checked', true);
}
});
I've also tried this and it won't work to start with.
$(".filter-wrapper-f").click(function(){
var $checkbox = $(this).children(".checkpic");
if ($checkbox.prop('checked', true)){
$checkbox.removeProp('checked');
} else {
$checkbox.prop('checked', true);
}
});