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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:06:22+00:00 2026-05-17T17:06:22+00:00

I am trying to use Jquery to resolve my below issue. I have got

  • 0

I am trying to use Jquery to resolve my below issue.

I have got below HTML Links.

<ul class="tabHead tabs-nav"> 
    <li class="tabs-selected" id="tab-1">
    <a id="tab1" class="load-fragment" href="/index.aspx"><span>Overview</span></a>
    </li>
    <li id="tab-2">
    <a id="tab2" class="load-fragment" href="/guide.aspx"><span>Guide</span></a>
    </li>
    <li id="tab-3">
    <a id="tab3" href="/flightschedule.aspx"><span>Flight Schedule</span></a>
    </li>
    <li id="tab-4">
    <a id="tab4" href="/specialOffers.aspx"><span>Special Offers</span></a>
    </li>
    <li id="tab-5">
    <a id="tab5" class="load-fragment" href="/photo.aspx"><span>Photos</span></a>
    </li>   
</ul>

First of all above HTML is generated dynamically, I have written a jquery on class=”load-fragment”, please see below

$(document).ready(function() 
{
        $(".load-fragment").each(function() 
        {           
            var fname = $(this).attr('href');
            var lastSlash = fname.lastIndexOf('/');
            var fileName = fname.substring(lastSlash+1, fname.lastIndexOf('.aspx')); //taking out filename for adding it in dynamic DIVs

            var dynDivID = "divContent"+fileName;
            $(this).attr("id",fileName)

            var newDiv = $("<div>").attr("id",dynDivID).load(fname + " #tabs-container",function ()
            {               
                $(this).hide();

            });      
            $("#column2").append(newDiv); //adding new div in div column2  
        });    

        $("#tab1").click(function()
        {
            // load home page on click
            $(this).attr("href", "#");
            $(".tabs-nav li").removeClass("tabs-selected"); //remove selected from other tabs
            $(this).parent().addClass("tabs-selected");
            $("#divContentindex").show();
            $("#tabs-container").hide();
            $("#divContentguide").hide();
            $("#divContentphoto").hide();
        });
        $("#tab2").click(function()
        {
            // load about page on click
            $(this).attr("href", "#");
            $(".tabs-nav li").removeClass("tabs-selected"); //remove selected from other tabs
            $(this).parent().addClass("tabs-selected");  
            $("#divContentguide").show();
            $("#tabs-container").hide();
            $("#divContentindex").hide();
            $("#divContentphoto").hide();
        });
        $("#tab5").click(function()
        {
            // load about page on click
            $(this).attr("href", "#");
            $(".tabs-nav li").removeClass("tabs-selected"); //remove selected from other tabs
            $(this).parent().addClass("tabs-selected"); 
            $("#divContentphoto").show();
            $("#tabs-container").hide();
            $("#divContentguide").hide();
            $("#divContentindex").hide();
        });

}); 

If you see above code, i have added the dynamic divs (divContentindex,divContentguide,divContentphoto) to DIV “column2“, I want to avoide the below code written above for hide and show for dynamic DIVs, I want it should also work as dynamic, there should not be any harcoded DIV ID as these ID are created dynamic above.

Please suggest!

Thanks.

Best Regards,
MS

  • 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-17T17:06:23+00:00Added an answer on May 17, 2026 at 5:06 pm

    Replace

    var lastSlash = fname.lastIndexOf('/');
    var fileName = fname.substring(lastSlash+1, fname.lastIndexOf('.aspx')); // ...
    var dynDivID = "divContent"+fileName;
    $(this).attr("id",fileName)
    

    By

    var dynDivID = "divContent"+$(this).attr('id');

    Add newDiv.addClass('dynDiv');
    before $("#column2").append(newDiv);

    And replace all

    $("#tabX").click(function() { ... });

    By

    $(".load-fragment").click(function() {
        // load about page on click
        var thiz = $(this);
        thiz.attr("href", "#");
        $(".tabs-nav li").removeClass("tabs-selected"); // ...
        thiz.parent().addClass("tabs-selected");
        $('.dynDiv').hide();
        $("#divContent" + thiz.attr("id")).show();
    }
    

    Should do the job (not tested)

    Edited according to comment

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

Sidebar

Related Questions

I'm new with javascript, so i'm trying to use two jQuery plugins, together they
I was trying to use the google maps API within some jQuery ajax, however
I´m trying to use jQuery-UI´s dialog to create a confirmation dialog attached to a
im trying to use jquery file upload to post files to a fileserver written
i am having trouble. i write HTML and jQuery and set same name attribute
I am trying to use Kangax's script from here: http://kangax.github.com/cft/ to detect those browsers
I am using Loading a partial view in jquery.dialog as a reference in order
I am trying to clone part of a form without including the information that
I am using ASP MVC with JQuery and posting json data to my controller.
i am trying to make a to do list app. When i click a

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.