I want to set a data-index
value of a parent element on one of its (nested) children. Desired result: string "index" should appear around the h2.heading
.
Markup:
<div class="foo" data-index="index">
<div>
<h2 class="heading"><span>title</span></h2>
</div>
</div>
CSS (the first data-index
rule works - but not in the right place):
div.foo[data-index] .heading span {
display: none;
}
div.foo[data-index]::after {
content: attr(data-index);
color: green;
}
div.foo[data-index] .heading::after {
content: attr(data-index);
color: red;
border: 1px solid red;
}