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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:50:39+00:00 2026-05-14T01:50:39+00:00

What I would like to do: use a single container to load images. As

  • 0

What I would like to do:
use a single container to load images.

As it is now:
I have eleven (11) containers in HTML mark-up each with its own div.
each container holds 4 images (2 images side by side top and bottom)
when link in anchor tag is clicked div with images fades in.

jQquery accordion is used for navigation typical example is:

<li>
  <a class="head" href="#">commercial/hospitality</a>
  <ul>
    <li><a href="#" projectName="project1" projectType="hospitality1" 
        image1="images/testImage1.jpg" 
        image2="images/testImage2.jpg" 
        image3="images/testImage3.jpg"
        image4="images/testImage4.jpg">hospitality project number 1</a>
    </li>

    <li><a href="#" projectName="project2" projectType="hospitality2"
        image1="images/testImage1.jpg" 
        image2="images/testImage2.jpg" 
        image3="images/testImage3.jpg"
        image4="images/testImage4.jpg">hospitality project number 2</a>
    </li>

    <li><a href="#" projectName="project3" projectType="hospitality3"
        image1="images/testImage1.jpg" 
        image2="images/testImage2.jpg" 
        image3="images/testImage3.jpg"
        image4="images/testImage4.jpg">hospitality project number 3</a>
    </li>
  </ul> 
</li>

Typical <div> container used for image insertion currently there are 11 of them:

<div id="hospitality1" class="current">
  <div id="image1"><img src="images/testImage.jpg"/></div>
  <div id="image2"><img src="images/testImage.jpg"/></div>
  <div id="image3"><img src="images/testImage.jpg"/></div>  
  <div id="image4"><img src="images/testImage.jpg"/></div>
</div>

Here is the code I am using at this point, it does work, but is there a better way
to do this that will only re-use a single div container for loading the images?

$(document).ready(function(){
  $('#navigation a').click(function (selected) {    

    var projectType = $(this).attr("projectType"); //projectType
    var projectName = $(this).attr("projectName"); //projectName

    var image1 = $(this).attr("image1"); //anchor tag for image number 1
    var image2 = $(this).attr("image2"); //anchor tag for image number 2
    var image3 = $(this).attr("image3"); //anchor tag for image number 3
    var image4 = $(this).attr("image4"); //anchor tag for image number 4

    console.log(projectType);   //returns type of project
    console.log(projectName);   //returns name of project
    console.log(image1);        //returns 1st image
    console.log(image2);        //returns 2nd image
    console.log(image3);        //returns 3rd image
    console.log(image4);        //returns 4th image

    $(function() {      
      $(".current").hide(); // hides previous selected image
      $("#" + projectType ).fadeIn("normal").addClass("current");

    });                     
});

As you can, see the mark up getting quite large.
Any help is appreciated.
ussteele

  • 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-14T01:50:39+00:00Added an answer on May 14, 2026 at 1:50 am

    You could do something like this with jQuery:

    $((function(){
      $('#navigation a').click(function (selected) {       
        $("#imgDiv").hide(); //Hide the div
    
        $("#projectName").text($(this).attr("projectName")); //Set name
        $("#projectType").text($(this).attr("projectType")); //Set type
        for(var i = 1; i<=4;i++) { //Replace Images
          $("#image" + i).attr("src", $(this).attr("image" + i);
        }
    
        $("#imgDiv").fadeIn("normal"); //Fade back in, only one - no need for current
      });                     
    });
    

    Using this html for your single div:

    <div id="imgDiv">
      <div id="image1"><img src="images/testImage.jpg"/></div>
      <div id="image2"><img src="images/testImage.jpg"/></div>
      <div id="image3"><img src="images/testImage.jpg"/></div>  
      <div id="image4"><img src="images/testImage.jpg"/></div>
      <span id="projectName"></span><span id="projectType"></span>
    </div>
    

    If I misunderstood, please comment and correct, we can definitely make this work with one div 🙂

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

Sidebar

Related Questions

I would like to use Linq to Xml to get a single XElement from
I would like to use a language that I am familiar with - Java,
I would like to use something like CLR Profiles on .Net 2.0 to see
I would like to use as and is as members of an enumeration. I
I would like to use a component that exposes the datasource property, but instead
I would like to use client-side Javascript to perform a DNS lookup (hostname to
I would like to use javascript to develop general-purpose GUI applications. Initially these are
I would like to use my laptop as a web development (PHP, Python, etc.)
I would like to use Emacs to edit some VB6 files but Emacs does
I would like to use VB9 but am not sure what syntax to use

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.