I have tables which are updating via dynamic ways. I want to change specific texts to colorful ones, during search operation in real time.
In this example, as you can see, it's possible to make them colorful for all document via smart way.
And this second example shows perfectly that how you can create a real time search engine for table
.
Now, here is the question: Is it possible to make that real time search's results colorfull? Not the whole column or row. I just need to change color value
of input
's matched value
. Long story short, how can I modify the 2nd example for this?
Here is the code: http://jsfiddle.net/e2106b62/2/
Classic tables I've used in HTML:
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
<input id="search">
JS I'm trying to use for search (You can find this on 2nd example link):
var $rows = $('#table tr');
$('#search').keyup(function() {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$rows.show().filter(function() {
var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(val);
}).hide();
});
And another JS which I need to implement in search module:
$(this).css('color', 'red');