I have a 4 col table, n rows.
<table border="0">
<tr><td><p>Cell 1 text</p> </td><td>chkbox in cell2</td><td><p>Cell 3 text</p></td><td>chkbox in cell4</td>
</tr>
</table>
I want to find and change CSS of previous cell on click of checkbox. So if checkbox in any row, cell 2 is clicked I need to act on contents of that row, cell 1, or if any row, cell 4 is clicked I need to act on that row, cell 3.
I have tried $(this).parents('td:first').find('p').text();
but this gets both cell 1 & cell 3
I do not really want to assign an id to all the cells. Any suggestions please?
To directly answer your question in the title, you can use the following:
$('checkbox').change(function() {
var prevCell = $(this).closest('td').prev();
// do stuff with prevCell
})
As for your problem in the description... Can't really understand them, could you post a more elaborate description?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With