I am trying to add a class when a checkbox is checked.
My jquery:
$('input').attr("checked").change(function(){
$('div.menuitem').addClass("menuitemshow");
})
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should not use
$("input")to select acheckbox, input will select all inputs. Instead you can useinput:checkbox:Basically what this does is execute whatever is inside the
function(){}when the checkbox is changed. Then you can just use jQueryisto check if the checkbox is checked or not..