Get one of checkbox value with multiple checkbox using jquery
I'm trying to get checkbox value from multiple checkbox.I have code as below:
<input class="ng-pristine ng-valid" type="checkbox" name="ch" value="a"
ng-model="todo.done">
<input class="ng-pristine ng-valid" type="checkbox" name="ch" value="b"
ng-model="todo.done">
<input class="ng-pristine ng-valid" type="checkbox" name="ch" value="c"
ng-model="todo.done">
<input class="ng-pristine ng-valid" type="checkbox" name="ch" value="d"
ng-model="todo.done">
what I want: when I check on checkbox,it will alert the value of checkbox.
I have jquery code as below:
$('input[type="checkbox"]').change(function() {
$('input[type="checkbox"]').each(function() {
if ($(this).is(':checked')) {
//the problem in here when I alert it will display many time with the
other value of checkbox
//what I need: I want to get only value of it when I check on it.
alert($(this).prop('value'));
}
});
});
Anyone please kindly help me, Thanks.
No comments:
Post a Comment