replit
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
JavaScript The Definitive Guide (15.3 Scripting Document)
Element
Last updated 2 years ago