如何区分原生 HTMLElement 和 created/custom 元素?
How to distinguish a native HTMLElement from a created/custom one?
假设我有以下 HTML 代码:
<header>
<nav>
<ul>
<li>My first menu</li>
<li>My second menu</li>
</ul>
</nav>
<header>
<main>
<section>
<h2>My title</h2>
<my-beautiful-text>My text</my-beautiful-text>
</section>
</main>
<footer>
Copyright © 2015
</footer>
当我循环所有元素时,我想知道元素(例如 nav
)是原生 HTML元素还是创建的元素(例如 my-beautiful-text
).
我已经在 Google 和这里搜索过,但没有找到。
我尝试使用 constructor
和 instanceof
,它适用于某些元素,例如 span
、div
、input
等,但是它不适用于某些不覆盖 HTMLElement
原型的组件。有什么猜测吗?
带有破折号的标签名称是自定义的。
假设我有以下 HTML 代码:
<header>
<nav>
<ul>
<li>My first menu</li>
<li>My second menu</li>
</ul>
</nav>
<header>
<main>
<section>
<h2>My title</h2>
<my-beautiful-text>My text</my-beautiful-text>
</section>
</main>
<footer>
Copyright © 2015
</footer>
当我循环所有元素时,我想知道元素(例如 nav
)是原生 HTML元素还是创建的元素(例如 my-beautiful-text
).
我已经在 Google 和这里搜索过,但没有找到。
我尝试使用 constructor
和 instanceof
,它适用于某些元素,例如 span
、div
、input
等,但是它不适用于某些不覆盖 HTMLElement
原型的组件。有什么猜测吗?
带有破折号的标签名称是自定义的。