Re: First-descendant-of-type selector?

----- Original Message ----- 
From: "Bjoern Hoehrmann" <derhoermi@gmx.net>
To: "dolphinling" <lists@dolphinling.net>


>
> * dolphinling wrote:
>>Suppose HTML were extended so that <li> had to be a descendant of <ul>, 
>>but not
>>necessarily a child: there could be another element (or multiple elements)
>>between them. Is there any way to reliably select the <li>(s) in that 
>>case?
>
> ul *:not(ul) > li { ... } /* or ...:not(ul):not(ol)... */
>
>>ul > li {}; obviously doesn't work, since li isn't the child.
>>ul li {}; doesn't work, because of the case <ul><foo><li><ul><li>
>>     (there's another list inside the one we're looking at)
>
> I assume that your selector only fails to meet your requirements because
> it selects the li in the inner list even though it is a child of the ul
> element. If that is not the problem, and you only want to look at outer
> lists, then this is impossible to achieve using CSS Selectors. Also note
> that there is generally no need to select the specific list items in one
> step, you could just combine
>
>  ul * li { ... }
>  ul > li { ... }
>
> or whatever you are really trying to achieve. If you need something more
> sophisticated, you should use a real selection language like XPath.

There are cases when CSS selectors can be used out of
context of CSS, cascading of attributes in particular.

Consider implementation of document.getElementBySelector() [1]
for example. The only way to implement nearest-child-of-its-kind
search is to use selector: X Y:not(Y Y)

For completness in mathematical sense selectors
"X Y" and "X>Y" should also have:
"X Y:not(X>Y)"

Y is child of X but not immediate.

Andrew Fedoniouk.
http://terrainformatica.com

[1] http://www.google.com/search?q=getElementBySelector


> -- 
> Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
> Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
> 68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
> 

Received on Thursday, 31 August 2006 02:55:25 UTC