0

As part of an upvote/downvote system (like on stackoverflow or Reddit) I'm using jQueries .css() property to change the background-position when an upvote or downvote arrow is clicked:

jQuery code:

$(document).ready(function() {
    $('#vpUp').click(function() {
        $('.vpVote').css('background-position','28 0;');
        var pId=1;
        vpVoteF(pId,1);
    });
    $('#vpDown').click(function() {
        $('.vpVote').css('background-position', '56 0;');
        var pId=1;
        vpVoteF(pId,-1);
    });
});

HTML:

<div class="vpVote">
    <div class="vpUD" id="vpUp"></div>
    <div class="vpUD" id="vpDown"><span id="vpVoteText"><?php echo $Votes; ?></span></div>
</div>

The background-position would change the background image to the upvote being highlighted or the downvote highlighted. However, the code doesn't seem to run at all. When I place an alert in either function it alerts when I click #vpUp or #vpDown, but they don't change the background position and in Chrome and Firefox with firebug open there are no errors.

I am completely at a loss.

Note: You can see a live demo of the voting (not) in action here: http://www.texturepacker.net/viewPacks2.php

2 Answers 2

5

Specify UNITS (px) with your position.

Sign up to request clarification or add additional context in comments.

1 Comment

And remove the ";" from the end. $('.vpVote').css('background-position','28px 0');.
2
$(document).ready(function() {
    $('#vpUp').click(function() {
        $('.vpVote').css('background-position','28px 0px');
        var pId=1;
        vpVoteF(pId,1);
    });
    $('#vpDown').click(function() {
        $('.vpVote').css('background-position', '56px 0px');
        var pId=1;
        vpVoteF(pId,-1);
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.