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
时间: 2024-10-16 16:45:18