3

Possible Duplicate:
jQuery voting system

i have this voting jquery script, which works fine, but i want the option for the user to toggle the vote, just like stackoverflow, so basically

you can vote up by clicking up arrow
   increase vote by 1
   if they click again on the picture(arrow up)
   minus 1 from the vote

my jquery 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) {
                  // Not sure where your vote_count is. See the HTML for my placement
                $(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 code:

<span class="vote_count">0</span>
<a href="#" class="vote_up"><img src="img/uparrow.png" /></a>
<a href="#" class="vote_down"><img src="img/downarrow.png" /></a>

i was thinking what was the best way to do this thanks :))

Community
  • 1
  • 1
getaway
  • 8,792
  • 22
  • 64
  • 94
  • Please don't re-post the same question twice, especially using such vague subject lines as "jquery problem." Instead, use the "edit" feature on your question, combined with comments, to work toward your solution. You already asked here: http://stackoverflow.com/questions/3876084/jquery-problem and here: http://stackoverflow.com/questions/3868493/jquery-clicking-on-one-element-triggers-another – ChessWhiz Oct 06 '10 at 23:47

0 Answers0