You can try using jQuery eq ();
Given a jQuery object representing a set of DOM elements, the .eq () method creates a new jQuery object from a single element inside this set. The supplied pointer determines the position of this element in the set. JQuery documentation
<table> <tr class="test"><td>not this one</td></tr> <tr><td><a title="test">click</a></td></tr> <tr><td>not this one</td></tr> <tr class="test"><td>this one</td></tr> <tr class="test"><td>ignore this as well</td></tr> </table>
In the code, select brother 2ΒΊ with the class "test" in <tr>, which is one of the parents for the clicked <a> (red is the opposite, and you got your code):
$("a").on('click', function(){ $(this).parents("tr").siblings(".test").eq(1).toggle(); });
Check Pen!
teefars
source share