I would like to get a code snippet which demonstrates how to check if the tab is already opened.
I need the following functionality: 1.user click a button to add additonal tab 2.check if a tab with these title already exists 3.select existing tab if already exists otherwise add a new tab
Best regards, Javanus
Something like this:
var nameToCheck = "SomeNewTabName";
var tabNameExists = false;
$('#tabs ul li a').each(function(i) {
if (this.text == nameToCheck) {
tabNameExists = true;
}
});
if (!tabNameExist){
//code to insert new tab here
}
I'm going with the assumption that you are using jQuery UI tabs here...
Your solution to select the existing tab is a bit complex. The following line, to be placed just below tabNameExists = true;
, works fine and is very simple
$( "#tabs" ).tabs('option', 'active', i);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With