Suppose I select an item using $(mySelector) . I would like to select the closest title to it, so if the closest title element to it was <h2> , he would select it, but if the nearest was <h3> , he would choose it instead. How can i do this?
$(mySelector)
<h2>
<h3>
The comma in the selectors means "or." So you can do this:
$(mySelector).closest('h3, h2')
This will return 0 or 1 element closest if more than one match.
Source: https://habr.com/ru/post/1435554/More articles:where static objects are stored in java - javaGet data from a JSON object - jsonWhy doesn't the SMTP server receive a DATA command? - javaDo work every month on a specific day (using anacron?) - linuxHow to print a list as a string without parentheses - clojurePhoneGap app (Cordoba) / Kendo UI app locks when you click the ListView link - cordovaApplication.restart - Mysterious Behavior in VB.Net - vb.netCan Nsight Eclipse code in C ++? - c ++Returning a simple string in a Rest service doesn't return json? - javaRegexp shows unexpected type error in javascript - javascriptAll Articles