jquery if has parent

JavaScript
if ($(this).parents('.last').length) {
    // element has an ancestor element with the class "last"
}
Source

Also in JavaScript: