I'm trying to select a table cell which contains specific text but couldn't find out yet how it works: I'm having this code - but doesn't work:
var td = $("td:contains('MyCell')",tbl);
Any ideas what's wrong?
The example code below worked for me. Hope it helps....
<script type="text/javascript">
function getCell( cell )
{
var cell || '';
var result = $('tr').find('td:contains('+cell+')');
alert( $(result).text() );
}
<body onload="javascript:getCell('cell 4');">
<table width="30" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>cell 1</td>
<td>cell 2</td>
<td>cell 3</td>
</tr>
<tr>
<td>cell 4</td>
<td>cell 5</td>
<td>cell 6</td>
</tr>
<tr>
<td>cell 7</td>
<td>cell 8</td>
<td>cell 9</td>
</tr>
</table>
</body>
Maybe instead of the second parameter tbl
var td = $("#mySpecificTable td:contains('MyCell')");
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