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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:57:34+00:00 2026-06-10T01:57:34+00:00

On Stackoverflow site, the voting arrow initially it can be vote-up-off/vote-down-off if a user

  • 0

On Stackoverflow site, the voting arrow initially it can be “vote-up-off”/”vote-down-off” if a user hasn’t voted. It can also be one up / another down if the user voted before. Start from this 3 cases, upon the user click, I want to switch class. With help of nice people on this site, I arrived this code so far:

if($("a.vote-up-down").hasClass("vote-up-on")){
    $(".vote-up-on").removeClass("vote-up-on").addClass("vote-up-off");
    $(".vote-down-off").removeClass("vote-down-off").addClass("vote-down-on");
}
else if($("a.vote-up-down").hasClass("vote-down-on")){
    $(".vote-down-on").removeClass("vote-down-on").addClass("vote-down-off");
    $(".vote-up-off").removeClass("vote-up-off").addClass("vote-up-on");
}

This works if you don’t click up arrow again when it is already vote-up-on, or you don’t click down arrow again when it is already vote-down-on. Otherwise, it keeps switching disregarding the actual vote. If initially both arrow is off, this code will change both.
In my ajax function, I can provide response message of actual vote value ( 1 or -1), How can I correct the above code?

  • 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-10T01:57:35+00:00Added an answer on June 10, 2026 at 1:57 am

    The whole thing is easier if you don’t use vote-up-on and vote-down-on as different class names. Just toggle one class on: http://jsfiddle.net/ghSEb/.

    $(".vote").on("click", function() {
        $(".vote").not(this).removeClass("on");  // make sure to remove other vote
        $(this).toggleClass("on");​​​​​​​​​               // switch this one
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi Stackoverflow people, I am using the Userena package for my user registration site.
this is my first time posting on StackOverflow but this site is awesome. Thanks
Hi everybody of the stackoverflow community! I've been visiting this site for years and
Well, StackOverFlow is such a good site, most of my google search results direct
This is the URL I want to share: http://mydomain.com/#url=http://stackoverflow.com Inside my site, I do
I have searched the stackoverflow site to find if someone has recommended any good
For eg..in Stackoverflow site, after giving answer, if we are refreshing the page, it
Let's say I have a StackOverflow-esque site. I want to post a comment underneath
Example real site http://stackoverflow.com/ URL Masking http://masking.com/stackoverflow Question How to switch the URL masking
I'm trying to model a site similar to StackOverflow. It has a set of

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.