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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:48:19+00:00 2026-05-19T09:48:19+00:00

Ok, I tried this myself before posting here, but at this point I ran

  • 0

Ok, I tried this myself before posting here, but at this point I ran into a wall.

I have a list of products, each product has an ‘Add To Cart‘ button/image, and I want that image to be replaced with the ‘Item added to Cart‘ image.

The problem I have is that when I replace one image, all images are replaced. You can now tell how new to jQuery I am.

This is my jQuery:

//Replace the 'Add To Cart' button
 $('.add-to-cart-btn').click(function(){
   $('.add-to-cart-btn').replaceWith('<img src="images/button-added-to-cart.png" alt="Item added to Cart">');
 return false;
 });

Here’s my HTML:

<a href="#" class="add-to-cart-btn"><img src="images/button-add-to-cart.png" alt="Add to Cart"></a>

As you can see, I’m replacing the entire ahref element because when the item is added, I don’t want that button to be clickable again.

Any idea how to make just that one specific ‘Add To Cart’ button/image get replaced and not all the buttons?

Thanks for any help and guidance you can give me.

  • 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-19T09:48:20+00:00Added an answer on May 19, 2026 at 9:48 am

    You want to only replace the item that you selected (AKA, the item that was clicked), so don’t do the selection again and instead use the object that was clicked (this).

    //Replace the 'Add To Cart' button
     $('.add-to-cart-btn').click(function(){
       $(this).replaceWith('<img src="images/button-added-to-cart.png" alt="Add to Cart">');
     return false;
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to test this myself before asking on the forum but my simple
How can I code a stack in C++? I have tried this myself as
Before coming here, I tried myself by googling. After I read these two links
I have done this before, but still haven't mastered it. I downloaded a font
I have to admit that having not even tried to code this myself this
I tried this but it does not seem to be valid syntax. <xsl:element name=$myElementName></xsl:element>
I tried this, but could not get through:- code behind protected HtmlTableRow trComment; protected
I tried this: def str1=good stuff 1) def str2 = str1.replaceAll('\)',' ') but i
I think this has been asked before but even though I searched Google I
I set myself this rather simple sounding challenge but now I am stuck trying

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.