标签:selector div nbsp document htm doc tor cto innerhtml
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‘));
[Javascript] Finding Parent Elements
标签:selector div nbsp document htm doc tor cto innerhtml
原文地址:https://www.cnblogs.com/Answer1215/p/12596289.html