I have the following structure:
<div class="myClass">1</div>
<div class="myClass">2</div>
How can I select the first element matched by .myClass?
I know that I can do: [PARENT OF .myClass] .myClass:first-child {/* rules */} but I am curious if there is a pseudo CSS class that selects the first element matched by the selector.
Is that possible? How?
The jQuery selector would look like this: .myClass:first, but :first seems not to work in CSS.
first-child, otherwise there is thenth-child, which is somewhat more customizable, or thenth-of-typeselector that isn't supported in all older browsers.$('.myClass:first')or$('.myClass').first()(or other variations thereof)? Or, in plain JavaScript:document.querySelector('.myClass')?