 <p>You can simplify this a little bit.</p> <pre><code>function searchBox(inputVal) { var regExp = new RegExp(inputVal, 'i'); $('#boxdata').find('tr').removeClass('red').filter(function() { return $(this).find('td').filter(function() { return regExp.test( $(this).text() ); }).length &amp;&amp; $.trim(inputVal).length; }).addClass('red'); } </code></pre> <p>So remove the <code>red</code> class from all <code>&lt;tr&gt;</code>'s first, then filter them, test the text of each <code>&lt;td&gt;</code>, if it matches, return the <code>&lt;tr&gt;</code> and then add the class <code>red</code> again.</p> <h3><a href="http://jsfiddle.net/C72XK/9/" rel="nofollow">Here's a fiddle</a></h3> <p>As for changing from a <code>table</code> to <code>div</code>, the jQuery would depend on how you structure your markup, but the principle would remain the same.</p> <h3><a href="http://jsfiddle.net/C72XK/12/" rel="nofollow">Here's another fiddle</a></h3>