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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:00:58+00:00 2026-06-17T20:00:58+00:00

i try to add dynamic content to tabs and hide content if tab is

  • 0

i try to add dynamic content to tabs and hide content if tab is empty

html code

<ul id="tabs">
    <li><a href="#" name="#tab1">One</a></li>
    <li><a href="#" name="#tab2">Two</a></li>
    <li><a href="#" name="#tab3">Three</a></li>
    <li><a href="#" name="#tab4">Four</a></li>
</ul>

<div id="content_tabs">
    <div id="tab1">content 1</div>
    <div id="tab2">content 2</div>
    <div id="tab3">content 3</div>
    <div id="tab4">content 4</div>
</div>

js code

function resetTabs(){
    jQuery("#content_tabs > div").hide(); //Hide all content
    jQuery("#tabs a").attr("id",""); //Reset id's      
}

var myUrl = window.location.href; //get URL
var myUrlTab = myUrl.substring(myUrl.indexOf("#")); // For mywebsite. com/tabs.html#tab2, myUrlTab = #tab2     
var myUrlTabName = myUrlTab.substring(0,4); // For the above example, myUrlTabName = #tab

jQuery(function(){
    jQuery("#content_tabs > div").hide(); // Initially hide all content
    jQuery("#tabs li:first a").attr("id","current"); // Activate first tab
    jQuery("#content_tabs > div:first").fadeIn(); // Show first tab content

    jQuery("#tabs a").on("click",function(e) {
        e.preventDefault();
        if (jQuery(this).attr("id") == "current"){ //detection for current tab
         return       
        }
        else{             
        resetTabs();
        jQuery(this).attr("id","current"); // Activate this
        jQuery(jQuery(this).attr('name')).fadeIn(); // Show content for current tab
        }
    });

    for (i = 1; i <= $("#tabs li").length; i++) {
      if (myUrlTab == myUrlTabName + i) {
          resetTabs();
          jQuery("a[name='"+myUrlTab+"']").attr("id","current"); // Activate url tab
          jQuery(myUrlTab).fadeIn(); // Show url tab content        
      }
    }
});

beauty css

#tabs {
  overflow: hidden;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

#tabs li {
  float: left;
  margin: 0 -15px 0 0;
}

#tabs a {
  float: left;
  position: relative;
  padding: 0 40px;
  height: 0; 
  line-height: 30px;
  text-transform: uppercase;
  text-decoration: none;
  color: #fff;
  border-right: 30px solid transparent;
  border-bottom: 30px solid #3D3D3D;
  border-bottom-color: #777\9;
  opacity: .3;
  filter: alpha(opacity=30);      
}

#tabs a:hover,
#tabs a:focus {
  border-bottom-color: #2ac7e1;
  opacity: 1;
  filter: alpha(opacity=100);
}

#tabs a:focus {
  outline: 0;
}

#tabs #current {
  z-index: 3;
  border-bottom-color: #3d3d3d;
  opacity: 1;
  filter: alpha(opacity=100);     
}

here demo
http://jsfiddle.net/uVNFp/95/

appreciate if someone know how I do to hide content if tab is empty

Thanks

  • 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-17T20:00:59+00:00Added an answer on June 17, 2026 at 8:00 pm

    http://jsfiddle.net/tdf22/1/

    Changes from your original fiddle:

    • Removed contents of <div id="tab2">.
    • Added the following.
    $("#content_tabs > div:empty").each(function() {
        $("#tabs > li").eq($(this).index()).hide();
    });
    

    EDIT:

    In response to your comment about blank space, I created this fiddle:
    http://jsfiddle.net/tdf22/3/

    In this one, I:

    • added the following jQuery custom expression
    $.expr[":"].emptyOrWhiteSpace = function(obj){
      var $this = $(obj);
      return ($.trim($this.html()) === "");
    };
    
    • and changed this line

      $(“#content_tabs > div:empty”).each(function() {

    • to this

      $(“#content_tabs > div:emptyOrWhiteSpace”).each(function() {

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

Sidebar

Related Questions

If I try to add a tab to the toolbox and name it 'Clipboard
I try to add a class to a link with jquery <a rel=/Career/ href=/Career/></a>
I am using trimpath library to draw dynamic page I try to add expression
In this page there's a way to dynamic add html (textbox,input button and radio
I want to add dynamic literal control and dynamic button. so I try like
Today I try to make a dynamic dropdownlist using jQuery. I only provide one
I try to add a column to my datagrid using the follwing code, but
i try to add facebook like button on my root domain that will like
I try to add the android coverflow in my own android projet when myt
I try to add dots between the page title and the page number in

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.