In jquery, can I combine the “nearest” or “Parents” () with “hasClass”, so it will give me the closest element with the given class, if it exists on the page?
var matchingDiv = $(this).closest('div').hasClass('SomeClass') if ( matchingDiv != null ) {
I will always have either one matching div element or none. Thanks.
source share