Re: [csswg-drafts] [selectors] Parameterized selectors (#10567)

if I understand this premise right, I think this would be very useful. 

for example, I have a div. Inside I have a select and it can have a value of Apple, Orange, or Pear. 

Also within that div I have sub-fields that I want to show conditionally. So if the user selects Apple two extra Apple-specific fields appear below, if they select Orange oat Orange-specific field appears, if they select Pear nothing appears.

All the fields are present in the DOM, just display:none.

I could write a has selector:

`div:has(select[value=$dynamic-value]) .subfield[parent=$dynamic-value {
display:block;
}
`

where $dynamic-value is something that matches.

it doesn’t have to be value based either, it could be data attr or even class based maybe. Like in the case of selectedcontent having a span with a specific class, show any sub fields with that class.

Today I would have to write out a selector for every possible parent value with a corresponding child. most likely I would generate this via JS, but CSS is better 



-- 
GitHub Notification of comment by doesDesign
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10567#issuecomment-2727924785 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 17 March 2025 03:12:43 UTC