alert cheked checkbox by name or class

1

I need to show an alert when a checkbox is checked by the class or name, I tried to do the following without results thanks.

$('input[name="name_vh"]').on('click', function(){
  alert("chekeado");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<input class="class_vh" name="name_vh" type="checkbox">
<input class="class_vh" name="name_vh" type="checkbox">
<input class="class_vh" name="name_vh" type="checkbox">
    
asked by Javier Antonio Aguayo Aguilar 18.08.2017 в 18:41
source

1 answer

2

You can link it to the change event and launch the alert when this.checked is true, as follows:

$(".class_vh").change(function() {
    if(this.checked) {
    alert("chequeado");
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="class_vh" name="name_vh" type="checkbox">
<input class="class_vh" name="name_vh" type="checkbox">
<input class="class_vh" name="name_vh" type="checkbox">
    
answered by 18.08.2017 / 18:47
source