I have a jQuery function I wrote which will slideToggle an additional table row. There is a cell at the end of the clickable row that contains a button, however as the click of a container div triggers the function, clicking anywhere in the row will cause the new row to expand.
I need the function to only be triggered when the button is clicked as there is scope to add checkboxes, links etc to other parts of the table.
Code:
var toggleSpeed = 600;
var expandText = "more";
var collapseText = "less";
$(".extrainfo_container").click(function() {
$(this).find('.extrainfo').slideToggle(toggleSpeed);
if ($(this).find('.moreless').text() == collapseText) {
$(this).find('.moreless').text(expandText)
}
else {
$(this).find('.moreless').text(collapseText);
}
});
<table>
<tr>
<td>Header 1</td>
<td>Header 2</td>
<td>Header 3</td>
</tr>
</table>
<div class="extrainfo_container">
<table>
<tr>
<td>Col 1</td>
<td>Col 2</td>
<td><div class="moreless">more</div></td>
</tr>
<tr>
<td colspan="3">
<div class="extrainfo">
Extra information.<p />
Extra information.<p />
</div>
</td>
</tr>
</table>
</div>
Working example: http://jsfiddle.net/E22XR/69/
I have searched the forums, and although I did find similar questions and answers, none of them worked for me. I figure there must be something different I am doing, and/or there is a better way to achive the same result - I am quite new to writing my own functions.
If there is a better way, a requirement is that I do not use IDs as there could be any number of rows created dynamically.
.morelessinstead of.extrainfo_container. Then traverse the DOM to find the right element to show.