how to check SVG type in js
how to check SVG type in js
SVGSVGElement & SVGElement
svg = document.querySelector(`svg`);
// <svg class="icon" style="width: 100px; height: 100px;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3949">…</svg>
typeof svg;
// "object"
Object.prototype.toString.call(svg);
// "[object SVGSVGElement]"
svg instanceof SVGSVGElement;
// true
svg instanceof SVGElement;
// true
svg instanceof SVGAElement;
// false
svg instanceof HTMLElement;
// false
svg = document.querySelector(`svg`);
// <svg class="icon" style="width: 100px; height: 100px;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3949">…</svg>
typeof svg
// "object"
Object.prototype.toString.call(svg);
// "[object SVGSVGElement]"
svg instanceof SVGSVGElement;
// true
Web API
SVG DOM interfaces
https://developer.mozilla.org/en-US/docs/Web/API/SVGSVGElement
https://developer.mozilla.org/en-US/docs/Web/API/SVGAElement
https://developer.mozilla.org/en-US/docs/Web/API/SVGElement
SVG
https://developer.mozilla.org/en-US/docs/Glossary/SVG
https://developer.mozilla.org/en-US/docs/Web/SVG
https://developer.mozilla.org/en-US/docs/Web/SVG/Element
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg
js type checker
https://ioliu.cn/2016/judgment-variable-type/
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13726066.html
未经授权禁止转载,违者必究!