Reputation: 4534
Following code works inside the onchange property of checkbox:
onchange="if(this.checked)$('#row_date').show();else $('#row_date').hide();"
but jquery
alert($('#apply_range').checked) // throw undefined, either checked or unchecked
not working.
Upvotes: 0
Views: 310
Reputation: 92531
You have to either use $('#apply_range').is(":checked")
or directly access DOM element: $('#apply_range')[0].checked
.
Upvotes: 0
Reputation: 337580
checked
is a property of the DOMElement, not a jQuery object. To get that property from the jQuery object, use prop()
:
console.log($('#apply_range').prop('checked'));
Or you can access the DOMElement in the jQuery object directly like this:
console.log($('#apply_range')[0].checked);
// or
console.log($('#apply_range').get(0).checked);
Upvotes: 3