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

  • Home
  • SEARCH
  • 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 7986623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:54:26+00:00 2026-06-04T11:54:26+00:00

I’m trying to create a function that disables voting button after an Ajax POST

  • 0

I’m trying to create a function that disables voting button after an Ajax POST success. The voting buttons are enabled until POST completes, and then are fixed with ‘disabled’ styling and are in-clickable. I’m trying to use jQuery .not() to disable starting the function from clicked buttons (with the class ‘disabled’) but I’m not having much luck. Here’s a fiddle of my function so you can see my problem, I’m not sure what I’m missing but I’m hoping someone can help me find my error, it’s frustrating me : )

jQuery Code:

$("a.votebutton").not(".disabled").each(function(index) {
  var el = $(this);
  $(this).click(function() {
      el.addClass("active disabled").unbind("click");
      el.siblings().addClass("disabled");
  });
});

​

  • 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-04T11:54:28+00:00Added an answer on June 4, 2026 at 11:54 am

    The problem is that your code:

    $("a.votebutton").not(".disabled")
    

    selects all of the links that are not disabled at the time that line of code runs, and then you loop through assigning click handlers. These click handlers remain bound to those links even if they happen to be given the “disabled” class at a later time – so when you add the “disabled” class to the clicked element’s siblings those siblings still have a working click handler. If you unbind the click from the siblings that should fix it:

    // change
    el.siblings().addClass("disabled");
    // to be
    el.siblings().addClass("disabled").unbind("click");
    

    Note that you don’t need the .each():

    $("a.votebutton").not(".disabled").click(function() {
          $(this).addClass("active disabled").unbind("click")
                 .siblings().addClass("disabled").unbind("click");
    });
    

    Another way to do it would be to use delegated event handling:

    $("div.panel").on("click", "a.votebutton:not(.disabled)", function() {
       $(this).addClass("active disabled")
              .siblings().addClass("disabled");
    });
    

    That way the clicks are only handled once they bubble up to the containing div (“div.panel”), at which time your click handler is only run if the event’s source element matches the selector that is the second parameter to .on().

    Updated demo: http://jsfiddle.net/RSezp/2/

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

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.