let's say you have a list of links for simplicity: you can simply pass the index of the triggering element to the collection of all elements
<a href="#">...</a> <a href="#">...</a> <a href="#">...</a>
js (jQuery 1.7+, I used .on() otherwise use bind() ), the function may be
var triggers = $('a'); triggers.on('click', function(e) { e.preventDefault(); var index = triggers.index($(this)); /* ajax call passing index value */ });
so if you click on the passed index value of the third element, there will be 2. (index based on 0); Of course, this is true if the code (DOM) does not change. Later you can use this index to create a CSS rule for this element, for example. using :nth-child
Otherwise, if each of your elements has a different attribute (e.g. id), you can pass this attribute
example on JsFiddle: http://jsfiddle.net/t7J8T/
fcalderan
source share