$('tr:contains(Comedy)') and $(':contains(Comedy)','tr') are not the same.
When using "tr" as a context, you're searching it's children (the tds). So if you pass "td" as a context, the search will happen on it's children (which are none in your page). You need $('td:contains(Comedy)') or to exemplify the relationship, $ ('td:contains(Comedy)','tr') - ricardo On Dec 20, 7:04 pm, "chinnakarup...@gmail.com" <chinnakarup...@gmail.com> wrote: > Or rather the question should be > > can the :contains selector have a context for its search......and if I > make the 'this' to be it will it work..... > > On Dec 20, 1:43 pm, "chinnakarup...@gmail.com" > > <chinnakarup...@gmail.com> wrote: > > Hi, > > I am trying to match the content in 'td' and think the problem is with > > contains when it is trying to query withing 'td'.... > > > $(":contains('Comedy')",'td').css("background- > > color","green"); > > doesn't work... > > > but if I tried... > > $(":contains('Comedy')",'tr').css("background- > > color","green"); > > > this WORKS ....WHY....???? > > >http://chinnakaruppan.googlepages.com/index.html > > > Please find below the full code... > > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > > "http://www.w3.org/TR/html4/loose.dtd"> > > > <html xmlns="http://www.w3.org/1999/xhtml"> > > <head> > > <meta name="generator" content= > > "HTML Tidy, seewww.w3.org" /> > > <meta http-equiv="Content-Type" content= > > "text/html; charset=utf-8" /> > > > <title>New Web Project</title> > > <style type='text/css'> > > > </style> > > <script type="text/javascript" src="/lib/jquery/jquery.js"> > > </script> > > <script type="text/javascript"> > > $(document).ready(function(){ > > > $('tr td').filter(function(){ > > return $(':contains("History")',this); > > }).css("background-color","red"); > > > $("td:contains('Tragedy')").css("background-color","blue"); > > $('tr td').filter(":contains('Comedy')").css("background- > > color","green"); > > > }) > > > </script> > > </head> > > > <body> > > <table> > > <tr class="header"> > > <th>Title</th> > > > <th>Category</th> > > </tr> > > > <tr> > > <td>As You Like It</td> > > > <td>Comedy</td> > > </tr> > > > <tr> > > <td>All's Well that Ends Well</td> > > > <td>Comedy</td> > > </tr> > > > <tr> > > <td>Hamlet</td> > > > <td>Tragedy</td> > > </tr> > > > <tr> > > <td>Macbeth</td> > > > <td>Tragedy</td> > > </tr> > > > <tr> > > <td>Romeo and Juliet</td> > > > <td>Tragedy</td> > > </tr> > > > <tr> > > <td>Henry IV, Part I</td> > > > <td>History</td> > > </tr> > > > <tr> > > <td>Henry V</td> > > > <td>History</td> > > </tr> > > </table> > > </body> > > </html>