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

  • Home
  • SEARCH
  • 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 1083329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:25:15+00:00 2026-05-16T22:25:15+00:00

have a function in jquery to automatically create the tab elements for a product

  • 0

have a function in jquery to automatically create the tab elements for a product in ecommerce system.

function structureTabs()
{
    $('#tabs').prepend('<ul id="tabbtns"></ul>');

    $('#tabs h2').each(function(index){

        if(index > 0)
        {
            $(this).before('</div><div id="tabs-'+(index+1)+'">');
        }
        else
        {
            $(this).before('<div id="tabs-'+(index+1)+'" class="jackie">');
        }

        var title = $(this).text();

        $('#tabbtns').append('<li><a href="#tabs-' + (index+1) + '">' + title + '</a></li>');

    });

    $('#tabs').append('</div>');
}

You cannot put unclosed tabs into .before()??

Basically the content this is trying to wrap around is:

<div id="tabs">
<h2>Details</h2>
details text...
<h2>tech specs</h2>
tech spec text...
<h2>Video Sample</h2>
video embed url
</div>

The client of the eccomerce store can’t edit html, so need to build the tabs automatically in .js….

  • 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-16T22:25:15+00:00Added an answer on May 16, 2026 at 10:25 pm

    So to sum up all the other answers, I think the final script you are looking for would be something like this:

    $("#tabs h2").each(function(i) {
        $(this).nextUntil("h2").andSelf()
            .wrapAll('<div id="tab-'+ i +'"></div>');
    });
    
    $("#tabs").before('<ul id="menu"></ul>')
    $("#tabs > div > h2").each(function(i) {
        $("#menu")
            .append('<li><a href="#tab-'+ i +'">'+$(this).text()+'</a></li>');
    });
    

    There is just one little problem, though. It won’t work if you details text isn’t inside some html element. jQuery’s next or nextUntil function doesn’t recognise plain text as an element.

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

Sidebar

Related Questions

I have a webpage with multiple DIV elements. If i use the jquery function
I have this function in jQuery that gets data from a page with POST,
I have a function in jquery: $('#map').click(function(e) { var posX = $(this).offset().left, posY =
I have this jquery function that works, except I need to add something. I
I have a jQuery function that replaces thumbnails with the main image. This is
I have a jquery function in my script function test(){ $.ajax({ url: '/Customer/test' +
I have a jQuery function - this is the response that is it is
I have a jquery function for sending email with ajax request; function sendMail(from,to,subject,message){ var
I have a jQuery function already to perform the task I need but is
I have a click function in jQuery and it never seems to execute. I

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.