I have a checkbox like this...
<input type="checkbox" id="something" name="something" value="25" data-val="25" checked="checked" class="option">
<label for="something">Something</label>
I want to have javascript/jquery code where every time that checkbox is checked or unchecked, it looks to see if its checked and assigns a value of 25 if it's checked, or 0 if its not checked. However, when I test by checking/unchecking, it just keeps spitting out 25. Why isn't it changing to 0 when I uncheck? Any ideas what I'm doing wrong?
$( document ).ready(function() {
$('.option').on('change', function() {
if ($('#something').attr('checked')) {
var something = 25;
} else {
var something = 0;
}
console.log(something);
});
});