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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:01:46+00:00 2026-06-02T22:01:46+00:00

Note: Using a 3rd party tab system is not an option so please don’t

  • 0

Note: Using a 3rd party tab system is not an option so please don’t even recommend that.

On my page, I have several <div>s and several tabs. Each div can belong to multiple tabs. For example, all divs belong to the ‘All’ tab, and then some divs belong to the tab ‘Today’, some to ‘Tomorrow’, etc.

What I want to do is, when the user clicks the Today tab, I want to only show the divs which belong to that tab. When he clicks any other tab, then the previous tab’s divs should get hidden and the selected tab’s divs should show. Pretty standard tabbing behavior so far.

However where this is different is, one div can be shared between multiple tabs.

I was thinking that, whenever a new tab is selected, I could simply loop through all the divs of the last selected tab, hide them, and then loop through the current tab’s divs and show them.

However I’m wondering if there would be any more efficent / less CPU intensive method. Also, this method will cause some divs to be hidden only to then be showered again right away if they’re shared between the last tab and current tab. (For example: div_111 could be shared between Today and Tomorrow. User clicks Today, div_111 is shown. Then he clicks Tomorrow, div_111 is hidden at first, only to then be shown again).

Any suggestions?

  • 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-02T22:01:48+00:00Added an answer on June 2, 2026 at 10:01 pm

    The thing you want to watch out for is redraws. When you add or remove an element the browser has to figure out how the change affects every other element on the page, and reposition / resize every element accordingly. This process is almost always the most expensive part of a DOM manipulation – certainly more expensive than figuring out which elements go in which tabs.

    Browsers try to optimize redraws – they redraw as little of the page as possible, and sometimes group multiple changes into the same redraw. However, it is best to take matters into your own hands. You can make sure there are no more than two redraws, no matter how many nodes you add or remove, by first removing the parent node from the DOM, then making all your changes, then re-appending it. Here’s a simple example:

    var container = document.getElementById('container'),
        buffer = document.createDocumentFragment(),
        newNodes = tabs[selection], // an array or object, generated at page load,
                                    // containing all divs that show up in this tab
        i, div;
    document.body.removeChild(container);
    for (i = 0; div = newNodes[i]; i++) {
        buffer.appendChild(div); // if div is in container then it will be
                                 // automatically removed
    }
    container.innerHTML = ''; // probably more efficient to remove nodes individually
    container.appendChild(buffer);
    document.body.appendChild(container);
    

    Depending on your layout, removing container may cause the content below it to momentarily jump up. If you want a polished appearance you can either fix the height of container‘s parent or insert a placeholder in its place with container.parentNode.replaceNode().

    If you minimize redraws then you shouldn’t have any efficiency problems. But if you still want to tweak, sure, optimize your content insertion logic. The simplest way to do that would probably be to segregate content that is tied to a single tab from content that shows up in multiple tabs, possibly by using different containers for each content type. Remember that the best solution is the one that is no more generalized than it needs to be.

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

Sidebar

Related Questions

I am using a 3rd party platform to create a landing page, it is
I found the following claim in the documentation for Net::OpenSSH : Note that using
Note: I'm using Google Chrome Currently I have this test page http://www.evecakes.com/doodles/canvas_size_issue.htm It should
( Note : I'm using Scala 2.7.7 here, not 2.8). I'm doing something pretty
NOTE: I'm using a BSD based system so if I remember correctly this means
I need blitz++ to run a 3rd party library, but I'm not being able
Excluding any 3rd party extension not already bundled with PHP, Is there any method
I'm using some 3rd party javascript to generate a slideshows within each of the
NOTE: Using .NET 2.0, and VS2005 as IDE Hello all, I'm working on logging
Note: Using MySQL 4.0, which means no subqueries (at present). I have 2 tables:

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.