How can I select the first of the highest h*
elements present in a DOM?
Something like
(h1, h2, h3, h4, h5, h6):first-of-ordered-set
I.e. if a DOM tree has, in this order, h2
, h3
, h1
, h2
, h1
, it would select the first h1
;
and if the DOM has h3
, h3
, h2
, h2
, h4
, it would select the first h2
.
Let's assume h*
elements are not nested.
I suspect CSS doesn't have that power, right?
Somethink potentially usable: https://css-tricks.com/extremely-handy-nth-child-recipes-sass-mixins/
Edit: Why I want it: A CMS system takes this "first top heading" as a title of the document (post, page, ...). But it leaves it in the page. And then it shows the title twice - once as the post title and once in the body. JavaScript is removed. The top h*
level may differ.