I want to set a variable (pageselected) as per the checkbox click/unclick
event.
<thead>
<tr id="othercheckbox">
<th width="10"><input type="checkbox" name="zip" class="all" value="all" /></th>
</tr>
</thead>
$('#othercheckbox').click(function() {
if($(this).is(':checked')){
console.log("CCCCheckeddddddd");
that.pageselected = true;
}
else
{
console.log("UNCheckeddddddd");
that.pageselected = false;
}
}
But this is not behaving as expected. Where am I going wrong?
By using jQuery function prop() you can dynamically add this attribute or if present we can change its value i.e. checked=true to make the checkbox checked and checked=false to mark the checkbox unchecked.
To check whether a Checkbox has been checked, in jQuery, you can simply select the element, get its underlying object, instead of the jQuery object ( [0] ) and use the built-in checked property: let isChecked = $('#takenBefore')[0]. checked console. log(isChecked);
The jqxCheckBox checked event is triggered when the checkbox is checked.
prop() You can use the prop() method to check or uncheck a checkbox, such as on click of a button.
You are checking the row is checked or not, which is not possible.bind onchange
event on the checkbox. put it on the checkbox let say checkbox1.
<input type="checkbox" name="zip" id="checkbox1" class="all" value="all" />
$('#checkbox1').change(function(){
if($(this).is(':checked')){
console.log("CCCCheckeddddddd");
}
else
{
console.log("UNCheckeddddddd");
}
});
JSFIDDLE DEMO
Since the checkbox is inside the tr
with id othercheckbox
.. Use this
$('#othercheckbox input[name="zip"]').click(function () {
if ($(this).is(':checked')) {
alert("CCCCheckeddddddd");
//that.pageselected = true;
} else {
alert("UNCheckeddddddd");
//that.pageselected = false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With