Assume I select an element using $(mySelector). I would like to select the closest heading to it, so if the closest heading element to it was an <h2>, it would select that, but if the closest was an <h3>, it would select that instead. How can I do this?
Assume I select an element using $(mySelector) . I would like to select the
Share
The comma in selectors means “or”. So you may do this :
This will return 0 or 1 element, the closest if more than one match.