jqueryhtmlcssselectormultiple-entries

First of type for multiple elements selection


On the page I am working on the breadcrumbs at the top are shifted on some pages and fine on the others. I used a jquery command that set the offset of the breadcrumbs equal to the offset of the h1 element. This lines up the breadcrumbs with the header and the rest of the page. However some pages of h2 or h3 for the title. How can I select the first header element regardless of the number?

I'm trying to find something like: h1,h2,h3:first-of-type that would select the first occurrence of any 1 of these elements not all of them.


Solution

  • Use filter:

    $('h1,h2,h3').filter(':first')
    

    DEMO