Reputation: 3079
I'm using the iCheck jQuery library and can't seem to figure out a way to detect which element the event pertains to. Setting up any of the callbacks always returns every element, not just the one I clicked. I need to find which element was toggled, not all of them.
$("input").on('ifToggled', function(e){
console.log(this); //returns all 3 checkboxes below
console.log(e.currentTarget); //returns all 3 checkboxes below
console.log(e.target); //returns all 3 checkboxes below
});
<input type="checkbox" class="icheck" name="exercise[27][save_as_default]" style="position: absolute; opacity: 0;" value="1">
<input type="checkbox" class="icheck" name="exercise[498][save_as_default]" style="position: absolute; opacity: 0;" value="1">
<input type="checkbox" class="icheck" name="exercise[240][save_as_default]" style="position: absolute; opacity: 0;" value="1">
Upvotes: 2
Views: 888
Reputation: 61
you can also use class name instead of "input".
$('.icheck').on('ifToggled', function () {
if ($(this).prop("checked")) {
console.log($(this).val());
}
})
Upvotes: 1
Reputation: 3809
You can do that without any external library
$(".icheck").on('change', function(){
console.log(this.name);
});
Upvotes: 0