Re: Select a parrent node with s CSS selector?

Kang-min Liu wrote:

> Rather then use "<" to select parent element, I find it more sane  
> to use
> some special sort of mark the one you want in the search path of a  
> selection.
>
> I'd propose using a pair of () as the real target of a selector:
>
>    body>div.content (a:link) > p.description
>
> The overhead of this implementation may just be one more variable  
> to hold
> the target.

You meant this, right?

	body > div.content (p.description) > a:link

This idea was proposed a few years ago. I can't remember why it was  
dismissed or forgotten. I like the simplicity, but it may have had  
something to do with the use of :not(), :lang(), and other  
parenthetical patterns as selectors. Here is another option following  
that convention, :ancestor( anotherSelector ). What do you think?

If selecting the paragraph in:

	div.content p.description a:link

Use:

	div.content p.description a:link:ancestor(div.content  
p.description) /* more specific */

Somewhat verbose, but an established practice of limiting the  
ancestor path would make it much easier to parse. Therefore, it could  
be a "recommended coding practice" to always

Other options that would be harder to parse but effectively do the  
same thing once calculated:

	div.content p.description a:link:ancestor(p)
	a:link:ancestor(p.description)

Of course, it opens the floodgate to crazy selectors though...

	a:link:ancestor(p)+p:last-child:ancestor(div)>ul:nth-last-of-type(1)  
a.selected:ancestor(li):not([title="eatin ur foodz"])

Yikes!
James

Received on Tuesday, 24 April 2007 19:49:55 UTC