teh kc teh kc -5 years ago 96
jQuery Question

Only 1 upvote/downvote button are working

When I put 2 upvote/downvote button, then only the 1st button works. Check this. Does anyone know, how to fix it?

Answer Source

You have given both buttons same id while id of each element must be unique.

You can use a class to bind the click event and find the respective span and count the votes and show count of votes in that span.

Also you have only one counter i am not sure but i think if there are two separate buttons there should be two counters

$(".buttonup").click(function() {
  var vote = checkIfUserVoted() != votePlus ? votePlus : counter;
  localStorage.setItem("voted", vote);

Here is downvote button code

$(".buttondw").on('click', function () {
  var vote = checkIfUserVoted() != voteMinus ? voteMinus : counter;
  localStorage.setItem("voted", vote);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download