I have a page where I have multiple tables with data.
Fiddle:
DEMO
The <th>
is in a <tr>
with a class name and each of the rows have similar naming...
rowToClick1
rowToClick2
...and so forth.
Inside a for loop, where I generate data dynamically - I have <tr>
's with class names and similar to above they are named...
rowToExpand1
rowToExpand2
...and so forth.
Currently, my solution is working for expanding/collapsing these tables, but it is really ugly:
$('.rowToClick1').click(function () {
$(this).find('span').text(function (_, value) {
return value == '-' ? '+' : '-';
});
$(".rowToExpand1").toggle();
});
$('.rowToClick2').click(function () {
$(this).find('span').text(function (_, value) {
return value == '-' ? '+' : '-';
});
$(".rowToExpand2").toggle();
});
// Many more similar functions repeatedly, up to 20+ ..
How can I do this more efficiently?
Note: I don't want the tables to expand/collapse at the same time, but individually (like I do now).
Thanks in advance.