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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:43:08+00:00 2026-05-25T18:43:08+00:00

Sorry for the bad title wording! I have the JS: $(.add).click(function(event) { cid=event.target.id; alert(add

  • 0

Sorry for the bad title wording!

I have the JS:

$(".add").click(function(event)
{
   cid=event.target.id; 
   alert("add class changed");
   $("#"+cid).addClass("del");
   $("#"+cid).removeClass("add"); 
});


$(".del").click(function(event)
{
   cid=event.target.id; 
   alert("del class changed");
   $("#"+cid).addClass("del");
   $("#"+cid).removeClass("add"); 
});

And some html like this:

<a class="add" id="1" href="#">test a</a>
<a class="add" id="2" href="#">test b</a>
<a class="add" id="3" href="#">test c</a>

When I click on one of the “tests” I get the “add class changed” alert and the HTML shows it’s class has been changed to “del”.

However when I click on one of the changed “tests” the function for something with a del class doesn’t run, just the add one again.

So the class is changing and displaying accordingly, but the click function for the corresponding class isn’t happening.
Can anyone see where I’m going wrong?

EDIT:
Needed a “LIVE” event.
The following code works:

$(".add").live({
           click: function(event)
               {
                  cid=event.target.id; 
                  alert("add class changed");
                  $("#"+cid).addClass("del");
                  $("#"+cid).removeClass("add");
               }
               });
  • 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-25T18:43:09+00:00Added an answer on May 25, 2026 at 6:43 pm

    The $(".add") just selects elements that at that moment have the add class. It doesn’t mean the click event will magically be assigned to other elements when their classes change.

    This can be achieved, though, by using the JQuery live method to bind the events.

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

Sidebar

Related Questions

Sorry for the bad question title. Let's say that I have DateRange class that
At first sorry for my really bad title! If you have a better title
Sorry for the bad title, but I have no idea how to put this
First, sorry for bad title, couldn't come up with something more descriptive. I have
Sorry for the bad title, but I couldn't think of a better one. I'm
sorry for the bad title, I don't know how to describe my problem. I
Sorry the title isn't more help. I have a database of media-file URLs that
Sorry for the bad title (couldn't think of a better way to describe it)
Sorry for the bad title, if you can think of a better one, let
Sorry for the bad title, but... I tried git flow on a project I

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.