jquery - Keep count for element with different ids -
i trying create thumbs up/down rating demo http://jsfiddle.net/hfnl9/1/
var ups = 0; $('.rating .voteup').on('click', function () { var currentid = $(this).attr('href'); ups = ups + 1; $(currentid + ' > .up').html(ups); return false; }); var downs = 0; $('.rating .votedown').on('click', function () { var currentid = $(this).attr('href'); downs = downs + 1; $(currentid + ' > .down').html(downs); return false; });
however keeps count elements different ids, please see fiddle (click both thumbs ups or thumbs down see mean). how resolve this?
try this
$('.rating .voteup').on('click', function () { var = $(this).closest('div').find('.up'); up.text(parseint(up.text()) + 1); return false; }); $('.rating .votedown').on('click', function () { var down = $(this).closest('div').find('.down'); down.text(parseint(down.text()) + 1); return false; });
Comments
Post a Comment