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?
The comma in selectors means "or". So you may do this :
$(mySelector).closest('h3, h2')
This will return 0 or 1 element, the closest if more than one match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With