I am attempting to use some (simple) code to remove a JQuery UI tab that I had created dynamically. Unfortunately, it's not cooperating.
Here is the javascript method I'm using:
function removeTab(tabName) {
var tabIndex = -1;
$('#tabbedPanel > ul > li > a').each(
function(i) {
if (this.href == tabName) {
tabIndex = i;
}
});
$('#tabbedPanel').tabs("remove", tabIndex);
}
Unfortunately, all I get is "Object doesn't support this property or method". I'm sure that the tab index is correct.
Any help out there?
Glad you got it working.
One suggestion - instead of looping through the tabs, you can use the tabs API to figure out the selected index of the tab and remove it a lot easier.
Here's a fiddle I put together (using the jQueryUI demo tabs with some enhancements).
The key part is using the 'selected' option. I have a button that, when clicked, will alert the selected tab index...
$("#get_index").click(function(e) {
e.preventDefault();
alert("Selected tab index = " + $("#tabs").tabs("option", "selected"));
});
I have a different button that, when clicked, will get the selected index and then use the 'remove' option to remove that tab. This way you don't have to match the href name...
$("#remove_selected").click(function(e) {
e.preventDefault();
var selIndex = $("#tabs").tabs("option", "selected");
$("#tabs").tabs("remove", selIndex);
});
Even though you solved your problem, I thought I'd share this. Hope it helps!!
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