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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:39:02+00:00 2026-06-13T06:39:02+00:00

I have a slight problem with creating a tabbed interface. We are using a

  • 0

I have a slight problem with creating a tabbed interface. We are using a system that have a product’s content in only one text field when added to the catalogue. So the HTML markup looks like this, and can have both p and ul (even table) elements as content (no classes or id’s can be added unfortunately):

<div class="productDesc">
   <h1>Content 1</h1>
   <p>Content 1 content</p>

   <h1>Content 2</h1>
   <ul>
     <li>Content 2 content #1</li>
     <li>Content 2 content #2</li>
     <li>Content 2 content #3</li>
   </ul>

   <h1>Content 3</h1>
   <p>Content 3 content #1</p>
   <p>Content 3 content #2</p>
   <p>Content 3 content #3</p>
</div>

What I would like to be able to do is create a tabbed interface, so that each H1 element is a tab, and it’s content of course the content that should be displayed when the tab is clicked.

Is there a way to iterate through the HTML to get the end result looking like this for example:

<div id="tabs">
   <ul class="productTabs">
      <li><a href="#Content1">Content 1</a></li>
      <li><a href="#Content2">Content 2</a></li>
      <li><a href="#Content3">Content 3</a></li>
   </ul>
</div>

<div id="productDesc">
   <div id="Content1">
      <p>Content 1 content</p>
   </div>
   <div id="Content2">
      <ul>
         <li>Content 2 content #1</li>
         <li>Content 2 content #2</li>
         <li>Content 2 content #3</li>
      </ul>
   </div>
   <div id="Content3">
      <p>Content 3 content #1</p>
      <p>Content 3 content #2</p>
      <p>Content 3 content #3</p>
   </div>
</div>

Once I get the HTML markup fixed I should be able to make the tabs working.

  • 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-13T06:39:04+00:00Added an answer on June 13, 2026 at 6:39 am

    If you absolutely cannot change the generated markup:

    var productDesc = $('div.productDesc');
    var newProductDesc = $('<div/>').attr('id', 'productDesc');
    var tabs = $('<div/>').attr('id', 'tabs').insertBefore(productDesc);
    var productTabs = $('<ul/>').addClass('productTabs').appendTo(tabs);
    
    var i = 0;
    var lastTabContent;
    productDesc.children().each(function() {
        if($(this).is('h1')) {
            i++;
            $('<li/>').appendTo(productTabs).append($('<a/>').attr('href', '#Content' + i).html($(this).html()));
            lastTabContent = $('<div/>').attr('id', 'Content' + i).appendTo(newProductDesc);
        } else {
            $(this).appendTo(lastTabContent);
        }
    });
    productDesc.replaceWith(newProductDesc);
    

    jsfiddle

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

Sidebar

Related Questions

people. I have slight problem with GD2 text on image. I have everything working
Hey all, have a slight problem here. In CakePHP I have a controller that
I have a slight problem with creating a button on the server side code.
I have a slight problem. I am using a working script (works on my
I have a slight problem right now. Currently I have two classes. One called
Slight problem i have been pondering on, i have a class that loads a
I am creating a coverflow plugin but I have a slight problem when it
I have a slight problem with BufferedImage and JPanel. I am creating a game
I have a slight problem with a path: D:\\Music\\DJ Ti%C3%ABsto\\Tiesto\\Adagio For Strings (Spirit of
I have a slight problem... we made a change to our url structure the

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.