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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:44:14+00:00 2026-06-01T13:44:14+00:00

removeClass doesn’t remove the class selected from div.upvote in the js below, but addClass()

  • 0

removeClass doesn’t remove the class selected from div.upvote in the js below, but addClass() works fine. Why is that?

$(document).ready(function () {
"use strict";

    $('div.upvote').click(function () {
        var id = $(this).parents('li.book').attr('id');
        var vote_type = 'up';

        if ($(this).hasClass('selected')) {
            var vote_action = 'recall-vote';
            $.post('/b/vote/', {id: id, type: vote_type, action: vote_action}, function (response) {
                if ($.isNumeric(response)) {
                    $('li#' + id)
                        .find('div.upvote')
                        .removeClass('selected');
                    $('div.vote-tally span.num').html(response);
                }
            });
        } else {
            var vote_action = 'vote';
            $.post('/b/vote/', {id: id, type: vote_type, action: vote_action}, function (response) {
                if ($.isNumeric(response)) {
                    $('li#' + id)
                        .find('div.upvote')
                        .addClass('selected');
                    $('div.vote-tally span.num').html(response);
                }
            });
        }
    });
}
  • 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-01T13:44:16+00:00Added an answer on June 1, 2026 at 1:44 pm
    $(document).ready(function () {
        "use strict";
    
        $('div.upvote').click(function () {
            var id = $(this).parents('li.book').attr('id');
            var vote_type = 'up';
    
    
            if ($(this).hasClass('selected')) {
                var vote_action = 'recall-vote';
                (function (response) { // skip ajax, just call success callback
                    if ($.isNumeric(response)) {
                        $('li#' + id)
                                .find('div.upvote')
                                .removeClass('selected');
                        $('div.vote-tally span.num').html(response);
                    }
                }(123)); // fake numeric response
            } else {
                var vote_action = 'vote';
                (function (response) {
                    if ($.isNumeric(response)) {
                        $('li#' + id)
                                .find('div.upvote')
                                .addClass('selected');
                        $('div.vote-tally span.num').html(response);
                    }
                }(123));
            }
        });
    }) // ) missed
    

    HTML:

    <li id="li-id" class="book">
        <div class="upvote selected">upvote</div>
    </li>​
    

    With fake data all works fine. So you have a problem with non-numeric response or with missed )

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

Sidebar

Related Questions

The below code works fine in Chrome, but doesn't work correctly in Firefox. In
Something as simple as: $(#div).addClass(error).delay(1000).removeClass(error); doesn't seem to work. What would be the easiest
$(#tab1).click(function(){ loadTab(1); $('div.HOMEtabdiv ul.HOMEtabs a').removeClass('selected'); $(this).addClass('selected'); }); Would it be possible to make the
This function below works in static pages but in dynamic pages it doesn't work
$('#searchBox input').focus(function(){ console.log(true); $('nav').addClass('searching'); }); $('#searchBox input').blur(function(){ console.log(false) $('nav').removeClass('searching'); }); this works fine: adds
Something's not quite right here. $(document).ready(function() { $(a#edit).click(function() { $(div#search).addClass(hidden); $(div#edit).removeClass(hidden); alert((this).val()); return false;
I tried $(document).removeClass(myClassname) but it doesn't seem to work.
I have a piece of code that removes and add class 'selected' when the
$(.m).toggle( $(.m).addClass('on'), $(.m).removeClass('on') ); This doesn't seem to work the way I want it
I have a div with the class item. When I use .removeClass('item') on the

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.