[Javascript] Finding Parent Elements
const app = document.getElementById('app'); app.innerHTML = ` <h1>JavaScript DOM</h1> <div class="item"></div> `; const item = document.querySelector('.item'); console.log(item.parentNode); console.log(item.parentElement.parentElement); console.log(item.closest('#app')); console.log(item.closest('body')); 来源: https://www.cnblogs.com/Answer1215/p/12596289.html