I am trying to apply Javascript enabled rating to each of the responses to a post. Upon clicking a link, some elements are hidden and others are shown, and ratings are updated via Ajax. I added the partial count to IDs of HTML elements of each response so each of them have distinct IDs. But now how can I identify which link of which response has been clicked so that the JQuery code can process the elements associated to the relevant response? Is there a way to send IDs of links when they are clicked?
EDIT
The Toggle Function
(function($) {
return $.fn.clickToggle = function(func1, func2) {
var funcs;
funcs = [func1, func2];
this.data("toggleclicked", 0);
this.click(function() {
var data, tc;
data = $(this).data();
tc = data.toggleclicked;
$.proxy(funcs[tc], this)();
return data.toggleclicked = (tc + 1) % 2;
});
return this;
};
})(jQuery);
Usage
$('#link1').clickToggle(function() {
$('#link2').hide();
$('link3').hide();
$('#link4').show();
$('link5').show();
}, function() {
$('#link2').show();
$('link3').show();
$('#link4').hide();
$('link5').hide();
}
Check out this fiddle.
Using jQuery’s
on()method I’m listening for a click event on all anchor tags. In the click handler I’m grabbing the target and pulling its ID property.