2

假设我有以下 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)是本机 HTMLElement 还是创建的(例如my-beautiful-text)。

我已经在谷歌和这里搜索过它,但没有运气。

我的尝试是使用constructorand instanceof,它适用于某些元素,例如span,divinput,但它不适用于某些不覆盖HTMLElement原型的组件。有什么猜测吗?

4

1 回答 1

2

带有破折号的标签名称是自定义的。

请参阅规范http://w3c.github.io/webcomponents/spec/custom/

于 2015-08-31T13:07:40.580 回答