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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:40:15+00:00 2026-05-17T19:40:15+00:00

im trying to turn this jquery script into a toggle event type, thier is

  • 0

im trying to turn this jquery script into a toggle event type, thier is my script, with illustrations, to show what i want to happen. i cnt seem to intrgate it so here goes:

//myElement.toggle(vote(), unvote()); // this is the toggle event

    $(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();

//function vote () // this should be the vote up function
                //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");
                    }
                });

//function unvote() thier should be another function here to unvote toggle

$.ajax({
                    context: this,
                    type: "POST",
                      // Make sure "this" in the callback refers to the element clicked

                    data: "action=vote_down&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/uparrow.png");
                    }
                });
            });

i just dont know how to integrate this toggle event into this jquery snippet, someone please help me ive been trying for years :)) 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-05-17T19:40:15+00:00Added an answer on May 17, 2026 at 7:40 pm
    $('.statuses').delegate('.vote_up, .vote_down', 'click', function(e) {
        var parent = $(this).closest('.statuses'),
            vote = (($(this).hasClass("vote_up")) ? "up" : "down");
    
        if(parent.data("vote") == vote) {
            return true; // If already voted up, do nothing, if already voted down, do nothing...
        }
    
        if(vote == "down") { // Vote down
            src = "img/uparrow.png";
            action = "vote_down";
        }
        else if(vote == "up") { // Vote up
            src = "img/uparrowActive.png";
            action = "vote_up";
        }
    
        // Setting current vote (up or down)
        // So next time you toggle, we have the trace of the previous vote (up/down)
        // And authorise only do the opposite
        parent.data("vote", vote);
    
                $.ajax({
                    context: this,
                    type: "POST",
                      // Make sure "this" in the callback refers to the element clicked
    
                    data: "action=" + action + "&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", src);
                    }
                });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to turn this query into a view: SELECT t.* FROM user t
I'm trying to turn Etags off on iis 6 since I'm load ballancing multiple
Trying to get my css / C# functions to look like this: body {
Trying to keep all the presentation stuff in the xhtml on this project and
Trying to make a MySQL-based application support MS SQL, I ran into the following
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
I have page loading, via AJAX a PHP page into a div. In turn,
I am trying to create a go-moku game using jquery,php, and mysql database. I
I'm starting with jQuery and trying to save myself lots of code in a
I am trying to translate a function in a book into code, using MATLAB

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.