This is a follow-up to my question yesterday. The function adds to a counter and shows information when the star is clicked (and vice versa). Everything works fine.
New challenge: the function applies to individual entries in an activity feed and I’m trying to get it to work for each individual entry. Right now, if I click the star in one entry, the counter increases for all the entries. How can I get the jquery function to apply to each individual entry in the activity feed?
jQuery
$(function(){
$('.unstar').hide();
var count1=0;
$('.star').bind("click", function() {
if ($('.unstar').is(':hidden')) {
count1++;
$('.unstar').show();
$('.star_number').html(count1);
}
});
$('.unstar').bind("click", function() {
count1--;
$('.unstar').hide();
$('.star_number').html(count1);
});
});
Here’s the jsfiddle: http://jsfiddle.net/j5qAs/3/
Try this one
It adds a
.star-divwrapper around star and unstarIt uses HTML data, so you can set a default value
It uses jQuery context in selector (http://api.jquery.com/jQuery/#jQuery1)
http://jsfiddle.net/j5qAs/5/
HTML
javascript