admin管理员组文章数量:1403107
I need to process the DOM children of a container element (to achieve some fancy layout magic) and leave non-rendered elements alone.
I was surprised to find that I can't use an instanceof HTMLNoScriptElement
check for <noscript>
elements; which was my go-to solution for <style>
, <script>
, etc.
const shouldIgnoreElement = (element: Element) =>
element instanceof HTMLStyleElement ||
element instanceof HTMLScriptElement ||
element instanceof HTMLDialogElement ||
element instanceof HTMLTemplateElement ||
element.tagName === 'NOSCRIPT'
const shouldProcessElement = (element: Element) => !shouldIgnoreElement(element)
[...root.children].filter(shouldProcessElement).forEach(...)
As you can see I ended up using element.tagName === 'NOSCRIPT'
for the check. But I still want to get a deeper understanding of this curious situation. And wonder whether I did something wrong or harbor a misunderstanding.
My research on mdn turned up:
- the technical summary for
<script>
elements states their DOM interface isHTMLScriptElement
- the technical summary for
<noscript>
elements states their DOM interface isHTMLElement
- the Web API overview does not list any
HTMLNoScriptElement
So it seems there simply is no class
to represent <noscript>
elements.
Why is there no corresponding class?
Is noscript
the only HTML element type with this curious gap in the Web API?
本文标签:
版权声明:本文标题:javascript - Check if a DOM Element is <noscript> ; why can't I use instanceof HTMLNoScriptElement? - Stac 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744353497a2602186.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论