-
I am having a table cell with the heading Current Level.
-
An input textbox Basic
-
If the user enters any of the figures of the table cell in the input textbox, it would be highlighted.
-
I would like to highlight the immediate next cell value also.
here is what I try to achieve with a working demo.
please help me to achieve this
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<style>
.highlight
{
color:red;
background-color:yellow;
font-weight:bold;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6">
<table width="100%" border="0">
<tr>
<td>Basic</td><td><input class="form-control" type="text" name="cb" id="cb" autocomplete="off"/></td>
</tr>
</table>
</div>
</div>
</div>
<table class="table table-responsive">
<tr>
<td><h6>Current Level</h6></td>
</tr>
<tr>
<td>
<table id="le10" class="table table-responsive table-striped">
<tr><td>56100</td></tr>
<tr><td>57800</td></tr>
<tr><td>59500</td></tr>
<tr><td>61300</td></tr>
<tr><td>63100</td></tr>
<tr><td>65000</td></tr>
<tr><td>67000</td></tr>
<tr><td>69000</td></tr>
<tr><td>71100</td></tr>
<tr><td>73200</td></tr>
<tr><td>75400</td></tr>
<tr><td>77700</td></tr>
</table>
</td>
</tr>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!--match and highlight the Current basic textbox value with the level table-->
<script>
$(function(){
console.log('');
$('#cb').on('input', function() {
var textboxValue = $('#cb').val();
if(textboxValue.length>0)
{
$('#le10 td').each(function() {
var filter = textboxValue.toString().toUpperCase();
if ($(this).html().toString().toUpperCase().indexOf(filter) > -1) {
$(this).addClass('highlight');
} else {
$(this).removeClass('highlight');
}
});
}
else
{
$('#le10 td').removeClass('highlight');
}
});
});
</script>
</body>
</html>
2
Answers
If it doesn’t matter if the styling occurs on a td or tr, you can use this code to achieve it.
image
Reference: