Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I could be wrong, but the <a href="http://docs.jquery.com/Core/eq" rel="nofollow noreferrer">:eq positional selector</a> takes an integer <i>n</i> an finds the <i>nth</i> matching element. </p> <p>So if you said td:eq(1) -- you'd get the 2nd TD element in the table (second because the first index is zero/0).</p> <p>My guess is that you don't want to use the <a href="http://docs.jquery.com/Selectors/contains" rel="nofollow noreferrer">:contains selector</a> because you're looking for an exact string match and don't want partial matches.</p> <p>I'm not aware that jquery has a built in selector that will meet your needs (if so, please correct me). You could add one as an extension or use another method, such as an attribute selector to do the search for you.</p> <p>If you are able to control the generated HTML, you could add an ID attribute to each TD like so:</p> <pre><code> &lt;table id="servertable" border="1"&gt; &lt;thead&gt; &lt;tr&gt;&lt;th&gt;Server&lt;/th&gt;&lt;th&gt;Memory&lt;/th&gt;&lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt;&lt;td id="server_mars"&gt;Mars&lt;/td&gt;&lt;td&gt;4 GB&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td id="server_venus"&gt;Venus&lt;/td&gt;&lt;td&gt;1 GB&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td id="server_jupiter"&gt;Jupiter&lt;/td&gt;&lt;td&gt;2 GB&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td id="server_uranus"&gt;Uranus&lt;/td&gt;&lt;td&gt;8 GB&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td id="server_mars_2010"&gt;Mars_2010&lt;/td&gt;&lt;td&gt;4 GB&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;form&gt; &lt;label for="server"&gt;Find:&lt;/label&gt;&lt;input type="text" id="server" /&gt; &lt;button id="find"&gt;Find&lt;/button&gt; &lt;/form&gt; </code></pre> <p>The following attribute selector would locate the correct TD in the table:</p> <pre><code> &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $("#find").click(function() { var server = $("#server").val(); $("#servertable td").css("background-color", ""); // reset $("#servertable td[id='server_" + server.toLowerCase() + "']").css("background-color", "#FFFF00"); return false; }); }); &lt;/script&gt; </code></pre> <p>If you instead want to target the entire row that has the TD that you're looking for, you can add additional selectors:</p> <pre><code> $("#servertable tbody tr").css("background-color", ""); $("#servertable tbody tr:has(td[id='server_" + server.toLowerCase() + "'])").css("background-color", "#FFFF00"); </code></pre> <p>The tbody tag isn't completely necessary, it just helps to distinguish between rows in the table body and rows in the table header.</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