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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:38:09+00:00 2026-05-22T12:38:09+00:00

I am allowing users to upvote an item. When they click the up arrow,

  • 0

I am allowing users to upvote an item. When they click the up arrow, I have jQuery change the class of the arrow so that it turns green. Now, if the user clicks that same arrow again, I want to create an event to change that arrow back to its original class, so they are undoing their vote (like stackoverflow voting: click once to upvote, click again to undo). Anyway here is my code.

These are the arrow classes in php generated on page load.

  <a href="javascript:void(0)" id = "' . $row['item_id'] . 'up"

        '; if ($row['upVote'] > 0) { echo '
            class = "used_upArrow"
           ';} else {echo '
               class = "new_upArrow"
               ';} echo '
                rowid="' . $row['item_id'] . '">
     </a>

Here is my jQuery changing the class on an upvote (among other things). This all works perfectly.

//upArrow
 $('.new_upArrow').click(function(){
   var row = $(this).attr('rowid');
    $.ajax({
    type: "GET",
    url: "upVote.php?id="+row,
    cache: false,
    async: false,
    success: function() {
        $('.'+row).html(parseInt($('.'+row).html()) + 1);
        document.getElementById(row+'up').className = "used_upArrow";
        },
    error: function(result){
        alert('Voting error, please try again.');
        }
     });
});

Here is where the undoing should occur. So, new_upArrow should now be used_upArrow, and this script should fire on click.

 $('.used_upArrow').click(function(){
   var row = $(this).attr('rowid');
    $.ajax({
    type: "GET",
    url: "downVote.php?id="+row,
    cache: false,
    async: false,
    success: function(result) {
        $('.'+row).html(parseInt($('.'+row).html()) - 1);
        document.getElementById(row+'up').className = "new_upArrow";
        },
    error: function(result){
        alert('Voting error, please try again.');
        }
    });
});

Checking firebug, the class is in fact changing FROM new_upArrow TO used_upArrow, but it continues to UPVOTE when clicked as if the class has no changed. Any ideas what is going on? Thank you in advance.

  • 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-22T12:38:09+00:00Added an answer on May 22, 2026 at 12:38 pm

    Use jQuery live event binding, eg

    $('.new_upArrow').live('click', function(){
    

    and

    $('.used_upArrow').live('click', function(){
    

    The reason your event binding isn’t working is because the normal bind, eg element.click() is processed only once at the time of execution.

    The live binder uses event delegation which will attach the handler to matching elements now and in the future.

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

Sidebar

Related Questions

I have a web app (sencha/phonegap) that includes a feature allowing users to click
I have implemented a javascript menu allowing users to change to different map views
I am allowing users to rotate images using jQuery rotate. However, when they do
I have a QTreeWidget which uses the QAbstractItemView.ExtendedSelection property, allowing users to shift click
I have task to write program allowing users to draw stars, which can differ
I have a little program allowing users to type-in some regular expressions. afterwards I
I have a simple page with a list of items. I am allowing users
I have some textboxes allowing users to enter numbers from 0 to 20. So
I have created an application where I am allowing users to log their Workouts.
I have a form allowing users to post an article. The article table is

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.