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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:51:33+00:00 2026-05-28T13:51:33+00:00

My problem is getting the first tab_content to show on load. my jquery: $(document).ready(function()

  • 0

My problem is getting the first tab_content to show on load.
my jquery:

$(document).ready(function() {

$(".tab_content").hide();
$("ul.tabs").each(function() {
    $(this).find('li:first').addClass("active");
    $(this).next('.tab_container').find('.tab_content:first').show();
});

My HTML:

<ul class="tabs">
    <li><a href="#tab1">web</a></li>
    <li><a href="#tab2">graphics/print</a></li>
    <li><a href="#tab4">img</a></li>
</ul>
<div class="gwrapper">
    <div id="gallery">
        <div id="image"></div>
        <div id="description">Welcome to my portfolio. Click any link below.</div>
    </div>
</div>

<div class="tab_container">
    <div id="tab1" class="tab_content">
        content
    </div>

The problem started when I moved the ul class=”tabs” above gwrapper (Used to be above tab_container). I know the problem is the selector in this line:

$(this).next('.tab_container').find('.tab_content:first').show();

I dont know how to jump divs and select. I’ve looked it up but I can’t piece it together. I dont know whether(or how) to use eq() in here.

Example can be found on jpatrolla.com (then click portfolio)

  • 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-28T13:51:33+00:00Added an answer on May 28, 2026 at 1:51 pm
    $(function() {
        $(".tab_content").hide();
        $(".tabs").each(function() {
            $(this).find('li').eq(0).addClass("active");
            $(this).nextAll('.tab_container').children('.tab_content').eq(0).show();
        });
    });
    

    The .tabs element and the .tab_container element in your example HTML are siblings, so you can use .siblings() or .nextAll() to select them relatively from your .tabs element. The difference between .siblings() and .nextAll() is that the latter only looks for elements that come after the current selection and the former looks at all sibling elements.

    Notice the usage of .eq(0) instead of :first, they do the same thing, select only the first element in the set, but using .eq() is faster since it doesn’t take mucking around with strings.

    Here is a demo: http://jsfiddle.net/YbNJ2/

    • Docs for .nextAll(): http://api.jquery.com/nextall

    UPDATE

    I normally like to help people optimize their code whenever possible and you can increase the performance of your loop by using either $.each() instead of $().each() or even better you can use a well formatted for loop:

    $(function() {
        $(".tab_content").hide();
        var $tabs = $(".tabs");
        for (var i = 0, len = $tabs.length; i < len; i++) {
            $tabs[i].find('li').eq(0).addClass("active");
            $tabs[i].nextAll('.tab_container').children('.tab_content').eq(0).show();
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first post on SO :-) I'm having a problem getting MooTools
I'm having a problem getting the root URL with this PHP function I composed.
I had tabs with preloaded content like this: $(function () { $('div.tabs ul.tabNavigation a').click(function
I am having a problem with Jquery Tabs. On my MVC page, I have
I've a really strange problem getting IIS7 to connect to Sql2008. First, using the
I have a major problem getting this to work properly. Here is the deal.
I was having a problem getting a function to accept an enum as a
Currently using HtmlUnit. Getting first login page is no problem, succesfully logging in, getting
Having a problem getting a TreeView control to display node images. The code below
I am having a problem getting a list of fields from a query defined

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.