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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:14:13+00:00 2026-06-08T11:14:13+00:00

I am using ajax to make a small voting app. When you click +1

  • 0

I am using ajax to make a small voting app. When you click +1 to vote up an item the following code runs, adding one to its vote count then the php returns a reordered list of items by votes. What I want is the voted up item to turn green. The code to change the colour will have to run after the items have been reordered and retrieved.

Below is one the block of code. Text in between is discussing what that particular part is doing.

$(function(){
  $(".plus").live('click', function() {
      var plus = $(this).data('plus');
      var dataString = "plus="+plus;

The next line of code gets the parent element of the clicked button with class .heading and animates its background colour to green to show it has been voted up. This works fine except that you only see it for a second because on success of item being voted up they are retrieved and output again to reorder them by votes.

$(this).parents(".itemheading").stop().animate({ backgroundColor: "#cdeb8b"}, 100);

        $.ajax({
      type: "POST",
      url: "bin/processButtons.php",
      data: dataString,
      success: function() {

        $.ajax({url: 'retrieve.php', dataType: 'json'}).done(function(data) {


            var html = data['html'];
            $('#content')
                .html(data['html'])

What I want to do is move the line of code to here so that it animates the colour AFTER the items have been voted up and then retrieved. This it no longer works because the $(this) needs to be done on the button just after it has been clicked.

 $(this).parents(".itemheading").stop().animate({ backgroundColor: "#cdeb8b"}, 100); 
    });
      }
     });
    return false;
    });
});

Thanks.

  • 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-08T11:14:15+00:00Added an answer on June 8, 2026 at 11:14 am

    Assuming I’m understanding your question correctly, you want to be able to keep $(this) for use later on?

    In which case, you should just be able to store it in a variable:

    var reference = $(this);
    
    //A chunk of code.
    
    $.ajax({url: 'retrieve.php', dataType: 'json'}).done(function(data) {
        //The HTML stuff...
        reference.parents(".itemheading").stop().animate({ backgroundColor: "#cdeb8b"}, 100);
    }
    

    Should do it.
    If you define reference in the function, you should be able to access it inside any AJAX success functions you define within that function (if that makes sense).

    The other way to do it is as we discussed in the comments below here – use your PHP to assign each answer a specific ID and store a reference to that instead…

    var reference = $(this).attr("id");
    //A chunk of code.
    
    $.ajax({url: 'retrieve.php', dataType: 'json'}).done(function(data) {
        //The HTML stuff...
        $("#" + reference).parents(".itemheading").stop().animate({ backgroundColor: "#cdeb8b"}, 100);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using jQuery mobile to make a small project. You can say its a
I'm using PHP and AJAX to make a post in a page. Below is
I want to make delete action asynchronous using AJAX, in the controller I make
I'm trying to to make AJAX call with the jQuery library using the $.ajax()
im using jquery to make ajax requests. is it possible to detect if the
I'm using jQuery to make an Ajax call using an Http Post in ASP.NET
I'm using prototype to make Ajax requests. Occasionally the responses contain malformed XML. Prototype
I am using this Ajax script below to make cross domain Ajax calls which
I am using asp.net mvc and jquery to make ajax requests and when the
I am trying to make an ajax call using $.get() where I want to

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.