I am trying to hide the tr having any td's value is Value1.
Below code is working fine. But, When I use variable instead of value, the code does not work.
I want it to work using variable.
<input type='button' value='hide/show' />
<table id="mytable">
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Value1</td>
<td>Value2</td>
<td>Value3</td>
</tr>
<tr>
<td>Value4</td>
<td>Value5</td>
<td>Value6</td>
</tr>
</tbody>
</table>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script>
var this_value = "Value1";
$('input').click(function()
{
// Working Fine with Value
$('td:contains("Value1")').parent().toggle();
// Not Working with Variable
// $('td:contains(this_value)').parent().toggle();
});
</script>
try this
var this_value = "Value1";
$('input').click(function()
{
$('td:contains('+this_value+')').parent().toggle();
});
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