This version is old school.
Please find jQuery plugins on npm.
jQuery Nearest Element
Find the elements in a page that are closest to (or furthest away from) a particular point or element, based on pixel dimensions
Find the elements in a page that are closest to (or furthest away from) a particular point or element, based on pixel dimensions