xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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 发布文章使用:只允许注册用户才可以访问!


posted @ 2020-09-24 19:31  xgqfrms  阅读(149)  评论(2编辑  收藏  举报