W3C home > Mailing lists > Public > www-style@w3.org > March 2010

Re: Select elements based on text content

From: Gabriele Romanato <gabriele.romanato@gmail.com>
Date: Mon, 29 Mar 2010 18:28:09 +0200
Cc: www-style@w3.org
Message-Id: <97620BE7-C0B6-4111-AE1A-ECE6BA02451E@gmail.com>
To: David Chambers <david.chambers.05@gmail.com>
Nope. This is somewhat that browser implementors would define  
"expensive", because it actually requires a full access to the DOM  
structure before the DOM is complete.  Example:

td --- #element
    Yes --- #text

var td = document.getElementsByTagName('tr') 
[1].getElementsByTagName('td');

for(var i=0; i < td.length; i++) {
   var yesNo = td[i].firstChild.nodeValue;
   // do a check here
}

regards :-)

On Mar 29, 2010, at 1:33 PM, David Chambers wrote:

> I've done some Google searches to find out whether this has been  
> discussed in the past, and failed to find anything. It's quite  
> possible, though, that I don't know the appropriate keywords.
>
> Here's an example:
>
> <tr>
>     <th>Chrome</th>
>     <th>Firefox</th>
>     <th>Internet Explorer</th>
>     <th>Safari</th>
> </tr>
> <tr>
>     <td>Yes</td>
>     <td>Yes</td>
>     <td>No</td>
>     <td>Yes</td>
> </tr>
>
> To apply styling to the noes, one could do the following:
>
> td.unsupported { font-weight: bold; color: red; } /* <td  
> class="unsupported">No</td> */
>
> Alternatively:
>
> td[rel="unsupported"] { font-weight: bold; color: red; } /* <td  
> rel="unsupported">No</td> */
>
> Does CSS3 include a selector which matches elements based on their  
> text content? It would be fantastic, in this example, to be able to  
> select all td elements whose text content is "No".
>
> David

http://www.css-zibaldone.com
http://www.css-zibaldone.com/test/  (English)
http://www.css-zibaldone.com/articles/  (English)
http://onwebdev.blogspot.com/  (English)
Received on Monday, 29 March 2010 16:28:48 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:25 GMT