Well i'm not really a guru in jQuery but i can do some basic stuff. However i can't get the point here. I'm listening to .btn-delete
click
event, setting .btn-danger
data-route
attribute (in the modal dialog) to the value of .btn-delete
data-route
attribute.
Really simple stuff, I know i'm doing it wrong. The value of data-route
for .btn-danger
does not change. Any help would be much appreciated, thanks.
<!-- modal confirm -->
<div id="modal-delete">
<a class="btn-danger" data-route="">Confirm</a>
</div>
<!-- delete buttons -->
<a class="bt-delete" data-route="/user/delete/1">Delete</a>
<a class="bt-delete" data-route="/user/delete/2">Delete</a>
<script>
$(document).ready(function() {
// Listen to .btn-delete click
$('.btn-delete').click(function() {
// Get data-route for the delete button and set it in the modal
$('#modal-delete .btn-danger')
.attr('data-route', $(this).data('ruote'));
// Do ajax in .btn-danger click event
$('#modal-delete .btn-danger').click(function() {
// data-route does not change
console.log($(this).data('route'));
});
});
});
</script>