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

  • Home
  • SEARCH
  • 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 3596934
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:03:11+00:00 2026-05-18T20:03:11+00:00

I’m just starting out with JQuery in a Drupal environment. I have some thumbnails,

  • 0

I’m just starting out with JQuery in a Drupal environment.

I have some thumbnails, and I want it so that when you click one, the bigger picture appears in the “viewport” (a hidden div appears). There might be better ways to accomplish what I am doing, but I need to do it this way.

This is what I have :

$(document).ready(function() {
  //$('#bigpic1').hide(); //show the first big picture always on page load
  $('#bigpic2').hide();
  $('#bigpic3').hide();

 $('a#thumb1').click(function() {
    $('#bigpic2').hide(); $('#bigpic3').hide();
    $('#bigpic3').toggle(200);
     return false;
  });
 $('a#thumb2').click(function() {
    $('#bigpic1').hide(); $('#bigpic3').hide();
    $('#bigpic2').toggle(200);
    return false;
  });
  $('a#thumb3').click(function() {
    $('#bigpic1').hide(); $('#bigpic2').hide();
    $('#bigpic3').toggle(200);
    return false;
  });

});

Besides being some ugly code, it doesn’t work right. The first big picture doesn’t appear when the page does, and clicking on more thumbnails shows the right div – but never hides any (only one big picture is supposed to be visible at a time in the “viewport”).

My HTML looks like this

<table><tr>
  <td><a href="#" mce_href="#" id="thumb1">...thumb1...</td>
  <td><a href="#" mce_href="#" id="thumb2">...thumb2...</td>
  <td><a href="#" mce_href="#" id="thumb3">...thumb3...</td>
</tr>
<tr><td colspan="3">
  <!-- my "viewport" cell -->
  <!-- the big picture displays here -->
  <div  id="bigpic1">... </div>
  <div  id="bigpic2">...</div>
  <div  id="bigpic3">...</div>
</td></tr></table>
  • 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-18T20:03:12+00:00Added an answer on May 18, 2026 at 8:03 pm

    The # selector selects an id so you don’t need the type in there. Selectors are on of jQuery’s best features, so get more familiar with them all. http://api.jquery.com/category/selectors/.

    You could even do a general method like this (you need to give the <a> elements a name).

    <table>
        <tr>
            <td>
                <a href="#" mce_href="#" name="thumb1" id="thumb1">...thumb1...</a>
            </td>
            <td>
                <a href="#" mce_href="#" name="thumb2" id="thumb2">...thumb2...</a>
            </td>
            <td>
                <a href="#" mce_href="#" name="thumb3" id="thumb3">...thumb3...</a>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <!-- my "viewport" cell -->
                <!-- the big picture displays here -->
                <div name="bigpic1" id="bigpic1">...1... </div>
                <div name="bigpic2" id="bigpic2">...2... </div>
                <div name="bigpic3" id="bigpic3">...3... </div>
            </td>
        </tr>
    </table>
    

    And the jQuery code.

    //on load
    $(document).ready(function() {
        $('#bigpic2').hide();
        $('#bigpic3').hide();
    
        //this will be run when an element has a name with the text "thumb" in it
        $('[name*=thumb]').click(function() {
            //hide all big pictures (loops over every element that has a name with the text "bigpic" in it
            $('[name*=bigpic]').each(function(index, value) {
                if ($(this).is(':visible')) { //if the big pic is visible
                    $(this).hide(200); //then hide it
                    return false; //found the visible big pic so no need to keep looping
                }
            });
            //show the right image
            $('#bigpic' + $(this).attr('id').replace('thumb', '')).show(200);
        });
    });// end on load
    

    This is less code, that is more extensible. It will not need to be changed if you add/remove images.
    About thie first image showing on load did you try $('#bigpic1').show(); on document load. Oh and you don’t need to return a value in the functions.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a JSP page retrieving data and when single or double quotes are
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am trying to loop through a bunch of documents I have to put

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.