Element.prototype.isInside = function(selector){
return this.closest(selector) !== null
};
function $(selector) {
return document.querySelector(selector)
}
document.body.isInside('html') // true
document.body.isInside('head') // false
$('body').isInside('html') // true
$('#p1').isInside('body') // true