I am trying to add a class when a checkbox is checked.
My jquery:
$(\'input\').attr(\"checked\").change(function(){
$(\'div.menuitem\').addClass(\"me
I'm making the assumption you'll want to toggle the class with the checkbox.
$('input').change(function(){
var $this = $(this), $div = $('div.menuitem');
if( $this.is(':checked') )
{
$div.addClass('show');
}
else
{
$div.removeClass('show');
}
}).change();
I've updated this to be a suggested solution @Rails beginner's issue given the comments I've read so far.
Note the addition of change() on the last line. This is to force change to execute immediately on page load (I'm assuming $('input') waits for document.ready or is after the input:checkbox is created).