how to get the value of a button that was pressed in a modal window?, I have tried it this way
$('#modalPregunta').on('show.bs.modal', function (evnt) {
var btnn = $(evnt.relatedTarget).find('button').val();
});
But I get undefined, my buttons are simple
<button type="button" id="btnsi" class="btn btn-primary" value="si">Si</button>
<button type="button" id="btnno" class="btn btn-danger" value="no">No</button>
What happened to you is that the
data-toggle
and properties are necessary for you to take the value with the .data-target
button
relatedTarget
I leave you an example working:
JS:
But
relatedTarget
it is already the button, you don't need to do the find()I solved it by placing other attributes (data-toggle, data-target, data-whatever) to the buttons, being as follows
and retrieving the value like so