I've done similar things before, click a checkbox then do something (.parent()
etc) but for some reason it's not registering this time. Can anyone see why?
$.each( email_list, function( key, value ) {
$("#email_span").after("<tr><td><input type='checkbox' name='member' checked='checked' onclick='check_change(this);' /></td><td>" + value.name + "</td><td>" + value.email + "</td></tr>");
$("#emails").prepend(value.email + ";");
});
$('.member').change(function() {
alert ("FECK");
if(this.checked) {
}
});
It is all within the $(document).ready
block. I've got it working with a function call but was curious why the jQuery .change
wasn't working?
prop() and is() method are the two way by which we can check whether a checkbox is checked in jQuery or not. prop(): This method provides an simple way to track down the status of checkboxes. It works well in every condition because every checkbox has checked property which specifies its checked or unchecked status.
With jQuery, you can use the . val() method to get the value of the Value attribute of the desired input checkbox.
The <input type="checkbox"> defines a checkbox. The checkbox is shown as a square box that is ticked (checked) when activated. Checkboxes are used to let a user select one or more options of a limited number of choices.
If the element has the 'change' event bound and if you need to fire the 'change' event after changing the checkbox property you can use the alt workaround below:
If you want to check:
$('#MyCheckbox input:checkbox').prop('checked', false).click();
If you want to uncheck:
$('#MyCheckbox input:checkbox').prop('checked', true).click();
it's using a reverse process. for the first one it will make sure the checkbox property is NOT checked, then it will trigger the click which will change the checkbox property to 'checked' then it will fire the 'change' event - if it's bound.
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