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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:59:28+00:00 2026-06-06T03:59:28+00:00

Basically, what I want to do is when a list item is clicked, an

  • 0

Basically, what I want to do is when a list item is clicked, an image is appended to the images div, and when it is toggled off, to remove the last image from the images div. So the more list item’s are added, the more images are in the div. When the list items are all toggled off, the number of images should be reset back to normal.

HTML

<ul id="list">
  <li><a href="#">First</a></li>
  <li><a href="#">Second</a></li>
  <li><a href="#">Third</a></li>
</ul>

<div class="images">
  <img src="#" />
  <img src="#" />
  <img src="#" />
  <img src="#" />
  <img src="#" />
</div>

jQuery

var count = 0;
$('#list a').on("click", function(event){
    count++;
    $(this).parent().toggleClass('added');
    var classname = $(this).parent().toggleClass('added');

    if (classname == '') {
      // remove image
    } else {
      //add image
    }

}

any ideas?

  • 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-06T03:59:29+00:00Added an answer on June 6, 2026 at 3:59 am

    Why not just loop through the image list to see if the source exists and leave classes out of it? Something like this maybe?:

    $('#list a').on("click", function(event){
    
        var src = $(this).attr('href'); // source of link clicked
    
        var addMe = 1;
    
        // loop through images list and look for clicked source
        $('.images img').each(function(i) {
            var $img = $(this);
    
            if ($img.attr('src') = src) { // found source matching <a href>
                $img.remove(); // remove the image
                addMe = 0; // stop image from adding
            } 
        });
    
        // if addme still = 1 append the html
        if (addMe) {
            var html = '<img src="'+src+'" />';
            $('.images').append(html);
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a list item expandable. Basically, I want to have a
Basically I want a list view(CheckBox and TextView) that has all the data from
Sorry for the poor title, basically I want to access a list item based
I want to create a custom list item. Basically it should 3 areas in
Basically, I want to get a list of all installed apps and pick one
I want to wrap around a list/vector in C++ like in Python. Basically I
I basically want to use the XML parser from Qt in my existing project.
Basically, I have a list: <li class=list>fruit</li> <li class=list>vegetables</li> <li class=list>protein</li> And, I want
I'm on MySQL 5.0. I basically have a List Item table and a List
This code basically fetches data from database and display it in a list along

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.