On Dec 20, 10:31 pm, chinnak <chinnakarup...@gmail.com> wrote:
> Thanks a lot ricardo..
>         $(':contains("History")','tr').css("background-color","red");
> (WORKS)
>
> One thing I understood was
> :contains uses the context to search in it children.not in the same
> element.becoz when I use 'td' as the context td has the text 'History' in it
> that I am looking for. Is this is a right statement???

Yes, but you can't find textnodes, only elements. If you had
<td><span>History</span></td> then $(':contains(History)','td') would
work.

>
> Also Can you do the same with filter function...Filter passes the 'this'
> which I assume to be element 'TR' here....
>
>     $('tr ').filter(function(){
>         return  $(':contains("History")',this);
>     }).css("background-color","red");
>
> This ends up making all rows red ...What is it I am not seeing....
> THanks once again...

For filter functions you need to return true or false, you're
returning a jQuery object:

$('td').filter(function(){
      return $(this).is(':contains(History)') //is() returns true/
false
});

But in this case you can use a selector in filter() directly:

$('td').filter(':contains(History)')

which doesn't make sense because it's exactly the same as

$('td:contains(History)')

You don't really need to use a context in this situation.

Hope I'm not confusing you.

- ricardo

Reply via email to