Here is fiddle and I have 2 divs one is outer box and another is the innerBox
, On clicking innerBox
I need to change the property of the outer box
.
As of css3 its not possible, so is anything available in css4?
The element>element selector is used to select elements with a specific parent. Note: Elements that are not directly a child of the specified parent, are not selected.
The element > element selector selects those elements which are the children of the specific parent. The operand on the left side of > is the parent and the operand on the right is the children element. Example: Match all <p> element that are child of only <div> element.
The :has() pseudo class is a selector that specifies an element which has at least one element that matches the relative selector passed as an argument.
There may not be such a thing as CSS4, but there is such a thing as "Selectors Level 4". This is an unfinished spec for the next generation of selectors, and does include a parent selector in the spec. Or more accurately, a "subject" selector.
The spec document is here: http://dev.w3.org/csswg/selectors/
But note that it is a dev URL, and the spec is still very much a work-in-progress.
In real code, the subject selector might look like this:
div > !.foo > span
This would select an element with the class foo
, that is a child of a div
, and has a span
within it as a child.
However as I said, this is not a finished spec (indeed, the syntax for the subject selector has changed more than once during the process, and may still be subject to further change at any time). It is also not implemented yet in any of the browsers, and there is no expectation of it being so either any time soon.
In addition, even if/when Selectors Level 4 is implemented in the browsers, the spec explicitly states that some selectors can be left out of the implementation for performance reasons (they differentiate between 'fast' selectors and the 'complete' set of selectors). The subject selector is one of these: If the spec remains as is, then browsers would have no compulsion to add it to CSS. In this case, they would maybe add it to Javascript, ie for methods like document.querySelector()
but not to CSS itself. This wouldn't really help you in any way, since it's already possible to find a parent element via javascript anyway. (See section 2.1 in the spec linked above for more on this).
So the short answer is: No, it isn't possible. It may be possible in the future, but that doesn't help you now, and even in the future there may be show-stopping caveats.
(you may also like to read this article which is a more end-user-friendly document than the actual spec. But you'll note that the subject selector syntax has changed since this article was written)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With