Im confused why this isnt working and am not able to debug
I have a set of checkboxe’s grouped by an attribute value
and have a checkall class at the foot of each group with matching attribute value when i click this i want to toggle the other checkboxs to same state
jquery
$(function () {
$('.checkall').click(function () {
var myactivemonth=$(this).attr("data-mymonth");
console.log(myactivemonth);
var myactivebox="a_"+myactivemonth;
$('checkbox[data_mymonth=myactivemonth]').attr('checked','checked');
});
html
<input id="alloInv" class="tip_trigger" type="checkbox" data-mymonth="a_October2012" title="13.94" value="2018441" name="alloInv">
<input id="alloInv" class="tip_trigger" type="checkbox" data-mymonth="a_October2012" title="10.94" value="201845" name="alloInv">
<input class="checkall" type="checkbox" data-mymonth="October2012">
IT appears all ok but the boxes aren’t ticking 🙁
You have a series of wrong things
checkboxshould be:checkboxdata_mymonthshould bedata-mymonthmyactiveboxneeds to be passed dynamically});A couple of improvements as well
.prop()instead of.attr()for actual properties of the element.$(this).data('mymonth');.data()to retrieve values fromdata-attributesSo
Working demo at http://jsfiddle.net/6Nv3N/
Update
I missed the toggle part of your question
To handle toggling the checkboxes you need to set the
checkedproperty to that of the.checkallelement.The
.prop()way (demo)The
.attr()way