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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:41:58+00:00 2026-05-15T00:41:58+00:00

I have a layout roughly as follows: <div id=foo> <!– a bunch of content

  • 0

I have a layout roughly as follows:

<div id="foo">

    <!-- a bunch of content -->

</div>


<div id="thumbnails">
    <div class="thumb-content1"></div>
    <div class="thumb-content2"></div>
    <div class="thumb-content3"></div>
</div>


<div id="content-1">
    <!-- some text and pictures, including large-pic1 -->
</div>

<div id="content-2">
    <!-- some text and pictures, including large-pic2 -->
</div>

<div id="content-3">
    <!-- some text and pictures, including large-pic3 -->
</div>

etc ....

On page load I want to show ‘foo’ and ‘thumbnails’ and hide the three content divs.

As the user clicks each thumbnail, I want to hide foo, and replace it with the matching ‘content-x’.

I can get my head round jQuery show, hide and replace (although, bonus points if you want to include that in your example!). But how would I extract and construct the appropriate content id, from the thumbnail class, then pass it to the show hide code?

  • 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-15T00:41:58+00:00Added an answer on May 15, 2026 at 12:41 am

    Based on your markup, you can do something like this:

    $("[id^=content]").hide();
    $("#thumbnails > div").click(function() {
        var id = $(this).attr('class').replace('thumb-content','');
        $("#foo").html($("#content-"+id).html());
    })​​​​​​​​​​​​​​​​;​
    

    You can see a demo working here

    This uses the ^= starts-with selector to hide the initial divs, and on click, uses .html() to copy the content like you want.

    If you have a lot of these, it’s better to use .delegate(), which attaches a single event handler instead of n event handlers to every click-able <div>. It would look like this:

    $("[id^=content]").hide();
    $("#thumbnails").delegate("div", "click", function() {
        var id = $(this).attr('class').replace('thumb-content','');
        $("#foo").html($("#content-"+id).html());
    });​
    

    Demo updated for that here

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

Sidebar

Related Questions

I have the layout as follows: <div id=outerwrap> <div id=innerwrap> <div id=centerc>...</div> <div id=rightc
say I have layout like so: <div id=main> <div id=NormalContent> {some content which is
I have layout as follows. Height of resizeable element is to kept such as
I have a visual studio solution whith (roughly speaking) the following layout: Common.dll Proja
I have layout which contains a header, content in the scrollview and a footer.
I have a class with a static method that looks roughly like: class X
I have this on my controller: class EmployeeAccountsController extends AppController { var $layout =
I have this _Layout.cshtml <body> <div id=wrapper> <div id=header-wrapper> <div id=header> <div id=logo> //SOME
I have a Layout containing a fragment. I set width of Layout to let's
I have this layout: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=match_parent android:layout_height=wrap_content android:orientation=horizontal android:gravity=left> <LinearLayout android:layout_width=wrap_content android:layout_height=wrap_content android:orientation=horizontal>

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.