[Javascript] Finding Parent Elements

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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‘));

 

以上是关于[Javascript] Finding Parent Elements的主要内容,如果未能解决你的问题,请参考以下文章

Finding distance between two curves

7.6 Models -- Finding Records

Finding Black Holes 1

FINDING THE FACTS

PAT 1108 Finding Average

Finding Nemo_BFS