My HTML structure looks something like below:
<div id="mainDiv">
<table></table>
<table></table>
<table>
<tr>
<td id="first">FirstCell</td><td id="second">SecondCell</td>
</tr>
<tr>
<td></td><td></td>
</tr>
</table>
</div>
Now I would like the find the content of second td based on the value of first td.
I have tried following but didn't seem to work.
$("#mainDiv tr td:contains('first')").each(function(){
var secondCell = $(this).find('#second').value();
});
Any help will be highly appreciated.
Based on your html structure you can achieve what you want like this
$("#mainDiv tr td:contains('First')").each(function(){
var secondCell = $(this).next().text();
console.log(secondCell);
});
Working Fiddle
Like @Blender said .value()
is not a function, use .text()
instead.
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