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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:25:52+00:00 2026-05-16T08:25:52+00:00

Hey guys, I have a little button functionality that is not erring, but also

  • 0

Hey guys, I have a little button functionality that is not erring, but also not working.
The addItem gets called fine, and switches the class from “add-button” to “in-cart-button”, but the $(“a.in-cart-button”).click(… doesn’t seem to be firing. When I click the “in-cart-button”, instead it triggers the addItem function again… Any ideas?

function addItem(t_id) {
    $("#" + t_id).addClass("in-cart-button").removeClass("add-button");
}

function removeItem(t_id) {
    $("#" + t_id).addClass("add-button").removeClass("in-cart-button");
    alert("Remove item with id: " + t_id);
}

$("a.add-button").click(function(event) {
    event.preventDefault();
    addItem(event.target.id);
});

$("a.in-cart-button").click(function(event) {
    event.preventDefault();
    removeItem(event.target.id);
});

Thanks!

  • 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-16T08:25:52+00:00Added an answer on May 16, 2026 at 8:25 am

    Instead of .click() which binds the elements when they’re found initially (by which classes they had initially), you would need .live() here, like this:

    $("a.add-button").live('click', function(event) {
    //and
    $("a.in-cart-button").live('click', function(event) {
    

    With .click() when the element’s class changes it doesn’t have an effect on the handlers, all that matters is which elements had the class when you called $("a.add-button") and $("a.in-cart-button"), it found the elements and bound to those…what happens to the element afterwards doesn’t matter, the handlers bound to the element, not the class. With .live() it checks the class when you click 🙂

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

Sidebar

Related Questions

Hey guys, have a little issue i need to figure out. I created a
Hey guys, I have a little issue here. I need my users to be
Hey Guys I have the following simple Code : WhereAmIViewController.h #import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h>
Hey guys, I have a client who wants their front site to have a
Hey guys, I have a question about Sphinx. I use Sphinx to index the
Hey guys, I have a bit of a weird problem. I have a jquery
Hey guys, so I have two models in my project, grinders, and votes. So
Hey guys. I have a question. I have two different arrays with different structure
hey guys, i'm getting an exception on the following inner exception: {Value cannot be
Hey guys i wrote a quick test. I want delete to call deleteMe which

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.