I do not think the problem is there, apparently you are using the id
in the buttons.
You are using the selector #
or selector for id : $('#btnCancelarFactura')
, but this selector returns 0 or 1 elements, not multiles. It means that only the first element found with id="btnCancelarFactura"
installs the driver and the rest do not install it; is done so, it is assumed that the ids
are unique.
There are two options, a selector by multiple for the attriute id
: notese [id=btnCancelarFactura]
$('button[id=btnCancelarFactura]').on('click',function () {
alert($(this).data("id"));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btnCancelarFactura" class="btn btn-warning" data-id=".234">1...</button>
<button id="btnCancelarFactura" class="btn btn-warning" data-id=".678">5...</button>
<button id="btnCancelarFactura" class="btn btn-warning" data-id=".012">9...</button>
or use a class, exclusive to these "cancel" buttons and select the elements, here the id does not need it.
<button class="btn btn-warning mibtn-cancelar" ... >
<button class="btn btn-warning mibtn-cancelar" ... >
Then you use the class selector and you take all the buttons.
$('.mibtn-cancelar').on('click',function () {
alert($(this).data("id"));
});
You were short, I recommend you always make sure via debugger that the selector is taking all the elements that you are expected to select.