Assuming this
refers to a DOM element that has a checked
property (for example, a check box or radio button), then the checked
property will be either true
if the element is checked, or false
if not. For example, given this HTML:
<input type="checkbox" id="example">
The following JS line will return false
:
var c = document.getElementById("example").checked;
Note that you wrote standard JavaScript, not jQuery. If this
refers to a jQuery object and not a DOM element, checked
will be undefined because the jQuery object does not have the checked
property. If this
is a jQuery object, you can use .prop
:
var c = this.prop("checked");
source share