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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:14:32+00:00 2026-05-17T03:14:32+00:00

i have this jquery voting script, everything is working fine, it just that the

  • 0

i have this jquery voting script, everything is working fine, it just that the image at the success function of the ajax request is not changing the image?

jquery:

$("a.vote_down").click(function(){
    //get the id
    the_id = $(this).attr('id');



    //the main ajax request
        $.ajax({
            type: "POST",
            data: "action=vote_down&id="+$(this).attr("id"),
            url: "votes.php",
            success: function(msg)
            {
                $("span#votes_count"+the_id).fadeOut();
                $("span#votes_count"+the_id).html(msg);
                $("span#votes_count"+the_id).fadeIn();
                            // this is my problem here
                $("span#vote_buttons"+the_id).attr("src", "images/downvoteActive.png");

            }
        });
    });

html:

<span class='vote_buttons' id='vote_buttons<?php echo $row['id']; ?>'>
        <a href='javascript:;' class='vote_up' id='<?php echo $row['id']; ?>'>Vote Up!</a>

        <a href='javascript:;' class='vote_down' id='<?php echo $row['id']; ?>'>Vote Down!</a>

css:

a.vote_up, a.vote_down {
    display:inline-block;
    background-repeat:none;
    background-position:center;
    height:16px;
    width:16px;
    margin-left:4px;
    text-indent:-900%;
}

a.vote_up {
    background:url("images/upvote.png");
}

a.vote_down {
    background:url("images/downvote.png");
}

        </span>
  • 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-17T03:14:32+00:00Added an answer on May 17, 2026 at 3:14 am

    UPDATE:

    Further to the updated question, span elements don’t have a src attribute.

    You also have another major issue. You are assigning the same id to more than one element: This is happening for the vote_up and vote_down links.

    From what I am understanding, you may want to simply assign a unique id to each vote_up and vote_down link, and them simply change their background url within the success callback.


    2nd UPDATE:

    Let’s assign a unique id to each vote_up and vote_down link:

    <a ... class='vote_up' id='vote_up<?php echo $row['id']; ?>'> ...
    <a ... class='vote_down' id='vote_down<?php echo $row['id']; ?>'> ...
    

    Then you can try to replace the problematic attr() call with this:

    $("#vote_up" + the_id).css("background-image", "url(images/downvoteActive.png)");
    

    Previous Answer:

    You’re trying to change the src attribute of a span element. I guess that should be an img, but you can leave out the tag name from the selector:

    $("#vote_buttons"+the_id).attr("src", "images/downvoteActive.png");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this jQuery script that works fine: $(select).change(function () { var finalPrice =
I have this jquery function that works, except I need to add something. I
I have this jQuery code: $(document).ready(function() { $.ajax({ url: pages/+page+.php, cache: false }).done(function( html
I have this jQuery code: <script type=text/javascript> $(function() { $(.one-edition img).hover(function() { $(this).next(.editions-info-text).show(); },
i have this jquery crossfade that is working for the most part except it
I have this jQuery AJAX code, when the request is successful, it does this:
I have this jQuery ajax call: $.ajax({ url : 'my_action', dataType: 'script', beforeSend :
I'm using jQuery AJAX to implement a voting system. I'm using this code: $(.vote_up).click(function(){
I have this JQuery code: jQuery(#form).click(function() { $(input[name='copyno']:checked).each(function() { checkboxData = copyno=+$(this).val(); id=$(this).val(); jQuery.ajax({
I have this jQuery function : $('a[name=pmRead]').click(function(e) { e.preventDefault(); $(this).parents(.pmMain).find(.pmMain5).toggle(); $.ajax({ type: 'POST', cache:

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.