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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:37:15+00:00 2026-06-04T08:37:15+00:00

Hi Im working on a project where on clicking an image will generate a

  • 0

Hi Im working on a project where on clicking an image will generate a summary about the image clicked. There is about 50 images that can be clicked.I want to append the summary in a list and I want to filter it so there wont be multiple appends if i click the image twice.

Here is the code for the html

    <div id="imageset">
       <img id="001" class="swatch" src="1.jpg" title="swatch 1" bigimage="1b.jpg"/>
       <img id="002" class="swatch" src="2.jpg" title="swatch 2" bigimage="2b.jpg"/>
       <img id="003" class="swatch" src="3.jpg" title="swatch 3" bigimage="3b.jpg"/>
       <img id="004" class="swatch" src="4.jpg" title="swatch 4" bigimage="4b.jpg"/>
       ....
    </div>
    <ul id="summary">
    </ul>

Here is the jQuery code

$("#001").click(function(){
   this.t = this.title;
   this.title = "";
   this.b = this.bigimage;
   this.bigimage = "";
   $("ul#summary").append("<li><div id='t001'>"+this.t+"</div></br><img id='b001' src="+this.b+"/></li>");
 });
$("#002").click(function(){
   this.t = this.title;
   this.title = "";
   this.b = this.bigimage;
   this.bigimage = "";
   $("ul#summary").append("<li><div id='t002'>"+this.t+"</div></br><img id='b002' src="+this.b+"/></li>");
 });
$("#003").click(function(){
   this.t = this.title;
   this.title = "";
   this.b = this.bigimage;
   this.bigimage = "";
   $("ul#summary").append("<li><div id='t003'>"+this.t+"</div></br><img id='b003' src="+this.b+"/></li>");
 });
 ........

and it goes on and on… Is there a way to simplify these codes? and if so how do i add an if and else statement to filter out if the content is already appended?

  • 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-06-04T08:37:16+00:00Added an answer on June 4, 2026 at 8:37 am

    If you’re adamant that you don’t want to use an AJAX request to fetch a greater wealth of possibly stored information from the server using something like a jQuery GET request, then you’d have to store the information somewhere on the page anyway, although if the code is being generated automatically then your life does become a lot easier and your jQuery code (at the very least!) can be simplified greatly!

    Using your existing HTML code above, consider the following jQuery code:

    $('#imageset img').click(function(){
    
        // get everything we need...
        var id = $(this).attr('id');
        var title = $(this).attr('title');
        var big_image = $(this).attr('bigimage');
        var list = $('#summary');
    
        // check to see if the list item already exists...
        var existing_item = $('#list_item_' + id);
        if (existing_item.length < 1)
        {
            // create the new list item...
            var new_item = $('<li />');
            new_item.attr('id', 'list_item_' + id);
            new_item.html('<div>' + title + '</div><br /><img src="' + big_image + '" />');
    
            // add it to the list...
            list.append(new_item);
        }
    });
    

    I hope this helps and makes sense! 🙂

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

Sidebar

Related Questions

Am working in a wordpress project. It uses many fash images. When right clicking
I'm working on a project that the user navigates around by clicking on icons
I'm working on a project that the user navigates around by clicking on icons
I'm working on project that lets users choose some scientific authors and columnists and
I am working a project with many NUnit tests, that were already written long
I am working on project in JSF, using Tomcat 7. The application will have
I have a fully working Setup project within Visual Studio 2008 that takes inputs
I'm working on a project that's trying to implement some editing features using a
I want it so when the x button is clicked a message box will
I'm working on a project that uses MOSS 2007. We have user profiles set

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.