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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:34:21+00:00 2026-05-17T16:34:21+00:00

I have got this script that works fine, that allows a user to vote,

  • 0

I have got this script that works fine, that allows a user to vote, but I’m kind of stuff of how I can make the vote button, when clicked again it toggle back to normal image! just like stackoverflow:

this is my script:

$(document).ready(function() {
    $('.statuses').delegate('.vote_up', 'click', function(e) {

        //stop event
        e.preventDefault();
       //get the id
        var the_id = $(this).closest('.message').attr('id').split('_').pop();
        //the main ajax request
        $.ajax({
            context: this,
            type: "POST",
              // Make sure "this" in the callback refers to the element clicked

            data: "action=vote_up&id=" + the_id,
            url: "ajax/votes.php",
            success: function (msg) {

                $(this).siblings("span.vote_count").html(msg).fadeIn();
                  // get the child <img> and set its src
                $(this).children("img").attr("src", "img/uparrowActive.png");
            }
        });
    });

html:

<ul class="statuses">
<li id="set_41" class="message">
 <span class="vote_count">0</span>
 <a href="#" class="vote_up"><img src="img/uparrow.png" /></a>

this is the pseudo language that I want to happen:

a user clicks vote image, it changes the image(uparrowActive)
//I've done that already
then
if user clicks the same image again it goes back to normal image(uparrow)
  • 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-17T16:34:22+00:00Added an answer on May 17, 2026 at 4:34 pm

    jquery has a toggle event that allows you to bind two event handlers to an element that are called alternately.

    *untested, probably has simple syntax errors.

    myElement.toggle(vote(), unvote());
    
    function vote()
    {
       // add a vote to the item
       // change icon to vote icon
    }
    
    function unvote()
    {
      // remove a vote from the item
      // change icon to default icon.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I have this script which works fine with IE but won't work
I have got this regex pattern that works with my current apache log format:
I have a script that works fine when I run it manually in R
This is the calendar script I got from an online tutorial. It works fine
I have a function written in coffeescript that used to work fine but now
I have this ajax_update script that updates file.php every 60 seconds.. Now file.php outputs
I have a bash shell script that loops through all child directories (but not
I've got a weird problem that I can't understand... I have a simple HelloWorld
I got this javascript code from off the internet. It's a script that changes
I have this jQuery which updates the DB on blur. It works fine except

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.