Reputation: 69
I have this code which is checking to see if a modal is open on the page. If a bootstrap is open i need to be able to get the name of it.
$(document).keypress(function (e) {
if (e.which == 13) {
var tf = $('div.modal').hasClass('in');
if (tf == true)
{
}
else
{
$('#search').click();
}
}
});
If you could provide with code that generates the ID of the currently open modal that would be great.
Cheers
Upvotes: 0
Views: 126
Reputation: 1503
Assign each modal with a unique id, and then find the id of the open-modal, and check in class their to identify modal is open or not.
$('div.modal.in').attr('id')
Upvotes: 1
Reputation: 4472
Using var activeModal_id = $('div.modal.in').attr('id');
Reference
Get the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element.
Upvotes: 1