I want to use the not: so it will exclude ALL the p elements within the div2 element. This is the html file:
<body>
<p> not in any div </p>
<div id="div1">
<p> div1 text1</p>
<div>
<p> div2 inner text2</p>
<div>
<p> div1 innermost text3</p>
<p> div1 innermost text4</p>
</div>
</div>
</div>
<div id="div2">
<p> div2 text1</p>
<div>
<p> div2 inner text2</p>
<div>
<p> div2 innermost text3</p>
<p> div2 innermost text4</p>
</div>
</div>
</div>
<div id="div3">
<p> div3 text1</p>
<div>
<p> div3 inner text2</p>
<div>
<p> div3 innermost text3</p>
<p> div3 innermost text4</p>
</div>
</div>
</div>
</body>
This is the CSSfile I use, (obviously) it's not working well:
div:not(#div2) p{
color:green;
}
This only excludes the p element with: "div2 text1" but not the other three within div2:
I believe this is because the "not:" only excludes the div2 div BUT NOT the two divs within it.
How do I change the context within the ":not" so it will include not only the div2 div BUT ALSO ALL the divs within div2 ?
What I am trying to do can be easilly achieve by using jQuery:
$('div p').not('#div2 p');
To summarize: How do I change this css line:
div:not(#div2) p{
So it will do (select) the same as the jQuery line? or in other words:
To select all p elements that are inside a div, unless it's div2. Or in other words:
To select all the p elements that contains either the word div1 or div3 (but without using this information)