Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>eq</code> expects a numerical index to only return a single row. If you want to match a td by its contents, you have to use the <a href="http://docs.jquery.com/Selectors/contains#text" rel="noreferrer">:contains</a> selector. Saying "it doesn't work" and throwing it away is not the right approach to the problem, as the selector is (most likely) not at fault (Do note its case sensitive, which might be it...)</p> <p>Anyhow, if you have a table like this:</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td&gt;Hello&lt;/td&gt; &lt;td&gt;World&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;World&lt;/td&gt; &lt;td&gt;Hello&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Hello&lt;/td&gt; &lt;td&gt;Hello&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>This jQuery code:</p> <pre><code>$(function() { $("td:contains('Hello')").css('color','red'); }); </code></pre> <p>Will turn all cells with "Hello" to red. <a href="http://jsbin.com/uzoxi" rel="noreferrer">Demo</a>.</p> <p>If you need a case insensitive match, you could do this, using the <a href="http://docs.jquery.com/Traversing/filter" rel="noreferrer"><code>filter</code></a> function:</p> <pre><code>$(function() { var search = 'HELLO'.toLowerCase(); $("td").filter(function() { return $(this).text().toLowerCase().indexOf(search) != -1; }).css('color','red'); }); </code></pre> <p>If you need to match the <em>exact</em> contents of the cell, you could use something similar to the above:</p> <pre><code>$(function() { var search = 'HELLO'.toLowerCase(); $("td").filter(function() { return $(this).text().toLowerCase() == search; }).css('color','red'); }); </code></pre> <p>The above is case insensitive (by turning both the search and the contents to lower case when comparing) otherwise you can just remove those if you want case sensitivity. <a href="http://jsbin.com/ofeca" rel="noreferrer">Demo</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload