Reputation: 4496
On my page I have two modal windows. They are opened when user clicks buttons on the page. But I also want to be able to open second window when user clicks specific button on the first modal. Here my JS code:
$(document).ready(function () {
$('.details-btn').on('click', function () {
$.ajax({
url: "/Device/Details",
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: 'html',
data: { id: $(this).attr('id') },
error: function (data) {
alert("wystąpił nieokreślony błąd " + data);
},
success: function (data) {
$('.modal-body').html(data);
$("#DetailsModal").modal('show');
$(".DeviceEdit-btn").on('click', function () {
$('#DetailsModal').modal('hide');
$("edit-btn").trigger('click');
});
}
});
});
$('.edit-btn').on('click', function () {
console.log("triggered");
$.ajax({
url: "/Device/Edit",
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: 'html',
data: { id: $(this).attr('id') },
error: function (data) {
alert("wystąpił nieokreślony błąd " + data);
},
success: function (data) {
$('.modal-body').html(data);
$("#EditModal").modal('show');
}
});
});
});
as you can in .details-btn
click event I hide a modal( this works) and trigger click on the button which should show second modal. But second modal doesn't show up.
How modify this code to make this work.
Is a problem connected with this that edit-btn
on click event is declared after details-btn
where trigger is?
Upvotes: 0
Views: 112
Reputation: 4621
Your are Not placing the dot
$("edit-btn").trigger('click');
change with
$(".edit-btn").trigger('click');
Upvotes: 2