Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9131669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:10:39+00:00 2026-06-17T08:10:39+00:00

I am using jQuery UI tabs in my web application, and I am loading

  • 0

I am using jQuery UI tabs in my web application, and I am loading each of the tab’s content dynamically via Ajax. This way, I can keep each tab’s content in separate HTML pages:

<div id="tabs">
  <ul>
    <li><a href="ajax/content1.html">Tab 1</a></li>
    <li><a href="ajax/content2.html">Tab 2</a></li>
    <li><a href="ajax/content3.html">Tab 3</a></li>
    <li><a href="ajax/content4.html">Tab 4</a></li>
  </ul>
</div>

The JavaScript to instantiate the tabs is in my index.js, with the HTML being in index.html.

Now, I want to create an addTabs() function in index.js that can be called from any of the tab content pages (content1.html, content2.html, etc.).

How can I do this? I tried creating the function in index.js and simply calling it with var id = addTab();. This did not work, though, as I recevieved an error: “Uncaught ReferenceError: addTab is not defined“. Here is the function:

function addTab(tabTitle) {
   // Add tab code          
   return id;
}

I also tried to use $.getScript() which will call the function, but I cannot access var id with what is returned outside of the $.getScript() function (I can only access it within the function).

I’d appreciate any help on the matter.


Here is the index.js file:

$(document).ready(

function () {

    var tabs = $("#tabs").tabs();

    tabs.tabs('option', 'selected', 2);

    var tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>";
    var tabCounter = 4;

    function addTab(tabTitle) {

        var label = tabTitle;
        var id = "tabs-" + tabCounter;
        var li = $(tabTemplate.replace(/#\{href\}/g, "#" + id).replace(/#\{label\}/g, label));

        // 3 fixed tabs + 5 dynamic tabs
        if (tabCounter > 8) {
            $("#dialog").html(
                    'You have reached the maximum number of tabs allowed.').dialog(
                    "open");
            return -1;
        }

        $("#tabId").replaceWith(
                '<input type="hidden" name="tabId" id="tabId" value="' + id
                        + '" />');

        tabs.find(".ui-tabs-nav").append(li);
        tabs.append("<div id='" + id + "'></div>");

        tabs.tabs("refresh");
        tabCounter++;

        return id;
    }

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:10:39+00:00Added an answer on June 17, 2026 at 8:10 am

    the addTab function should be outside of document.ready so other files can access it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a web application, and I am using the JQuery UI Tabs
I'm creating a web application which loads tabs using AJAX. My problem is that
I am using jQuery UI tabs. I have 10 tabs, and each tab holds
I have big web application using JQuery UI Tabs. In central JS file I
I'm using jQuery to create a load of tabs for a web application. I've
I am using jquery UI tabs I have three ajax tabs like so: <div
I have a perfectly working web page with using jQuery UI tabs on almost
I am using jquery tabs to load content from a remote file. I have
I'm using jquery tabs on a web page and when the page is refreshed
I have a web application (ASP.NET MVC3) which uses the jquery ui tab control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.