I would like to make add / remove a class to a div that holds a checkbox.
I am 80% there, though am not sure on the right syntax to look at whether the input item is checked or unchecked. So I can add or remove the class appropriate.
Essentially I know it needs to look like:
if("$thechecks #item-" + req).attr('checked') {
$("#item-" + req).addClass("item-select");
} else {
$("#item-" + req).removeClass("item-select");
}
Any help / thoughts would be really appreciated.
I made a small fiddle of my code to-date.
http://jsfiddle.net/brandrally/vc5wgpk2/
// Javascript //
$(document).ready(function () {
$("#thechecks input[type='checkbox']").click(function () {
var req = $(this).val();
$("#item-" + req).addClass("item-select");
});
});
// HTML //
<div id="thechecks">
<div id="item-1">
<label><input name="element[]" type="checkbox" value="1" > One</label>
</div>
<div id="item-2">
<label><input name="element[]" type="checkbox" value="2" > Two </label>
</div>
</div>