adding a background color to search term results
Posted
by turborogue
on Stack Overflow
See other posts from Stack Overflow
or by turborogue
Published on 2010-04-30T05:19:25Z
Indexed on
2010/04/30
5:27 UTC
Read the original article
Hit count: 199
I'm trying to add a background color to a user submitted search result when a user enters a search term on a page (which is basically one big table). This is a text based search. I'm using jquery to show/hide the table rows that do not have the search term as text within the TR, but I'd ideally like to take the additional step of taking the search term (the entered value), and matching any of those text terms in the remaining (showing) rows and adding say a yellow background to the word(s). I know my syntax is currently wrong, just not sure what is correct:) Hopefully this is clear...any help is greatly appreciated!
html of form:
jquery: $("#searchsubmit").click(function () { var searchexp = document.getElementById('searchbox').value; $("table tr").hide(); $("table tr.header").show(); $('tr:contains('+ searchexp +')').show(); $(searchexp).css('background-color','yellow'); });
© Stack Overflow or respective owner