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 5940071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:55:02+00:00 2026-05-22T15:55:02+00:00

I am dynamically adding tabs to my page using the following script: var tabs

  • 0

I am dynamically adding tabs to my page using the following script:

var tabs = $("#tabs");
$.each(results, function(index, item) {
    tabs.tabs("add","get_tab_content.aspx?tab=" + item.key, item.value);
});

where results contains json data.

This all works find, except for when I try to get the tab id via the following script:

$("li.ui-tabs-selected").attr("id")

That line returns nothing, as if an id is not set for the tabs in the loop above.

However, that line works fine if I manually type add tabs and ids e.g.

<div id="tabs">
    <ul>
        <li class="tab" id="tab_1"><a href="tab0.htm">Home</a></li>
        <li class="tab" id="tab_2"><a href="tab1.htm">Default</a></li>
    </ul>
</div>

For this manual html, the line $("li.ui-tabs-selected").attr("id") returns either tab_1 or tab_2.

How do I get the id of the tab from when I create tabs using the loop above? I am assuming I need to give them id’s when adding the tabs? But that is just an assumption. If that is the case, how do I give them ids?

  • 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-05-22T15:55:03+00:00Added an answer on May 22, 2026 at 3:55 pm

    It does not add ids because it does not need to.

    It uses the index of the tab to identify them.

    Why do you need to have an id on them ?


    update

    To add an id for each tab you can do the following (assuming that you use the code you provided in your question where the new tabs are added at the end by default)

    tabs.tabs("add","get_tab_content.aspx?tab=" + item.key, item.value)
        .find('>ul>li:last') // find the last li element, the tab we just added
        .attr('id',item.id); // use whatever id you want here ..i assumed you have an id in your json..
    

    example: http://jsfiddle.net/gaby/7Grb8/


    update 2

    if you want to do it with the index, then you should use the var selected = tabs.tabs( "option", "selected" ); as described in the docs

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

Sidebar

Related Questions

I'm dynamically adding a custom user control to the page as per this post
I m using jquery ui tabs and i m using them with the function
I am dynamically adding script tags to the DOM so I can download JSON
So I am adding text and textbox to a page dynamically if a checkbox
I am creating HtmlButton dynamically in .cs file. Adding it to Panel using HtmlButton
I'm building a list dynamically using: $(#Selected ul).append($liObject); Adding works, the issue is when
I'm having trouble dynamically adding controls inside an update panel with partial postbacks. I've
I have a flowpanel that I'm dynamically adding usercontrols to. I want it to
I am creating a Rails plugin and it is dynamically adding a method to
I am adding some user controls dynamically to a PlaceHolder server control. My user

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.