Reputation: 992
I have several checkboxes with the same classes. When I checked the box also checked other checkboxes with the same classes. Also i have event handler change
for checkboxes. After checked checkbox checked and others, all OK. But event handler called once. I need that called this event for each checkbox if this checkbox changed. How to do it?
My event handler:
$('input[type="checkbox"]').on 'change', checkboxClick
This checked or unchecked checkbox $(className).not(this).prop('checked', this.checked)
- this also changed checkboxes with the same ClassName, but for others except this
event handler not called.
Upvotes: 0
Views: 58
Reputation: 1
You can use Function.prototype.call()
to call named function checkboxClick
within event handler, instead of dispatching change
event
$(className).not(this).prop("checked", this.checked).each(function() {
checkboxClick.call(this)
});
Upvotes: 1
Reputation: 197
use .each function to apply all instances of that class.
$(className).each(function(){
$(this).prop('checked', true)
});
Upvotes: 0