Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.createElement("svg") instanceof SVGElement is false

When I tried the code document.createElement("svg") instanceof SVGElement in chrome it returns false. Why?

like image 557
Richeve Bebedor Avatar asked Jun 12 '14 01:06

Richeve Bebedor


1 Answers

Creating an element like <svg> not in any context and out of thin air will create an unknown element. If you want to create an SVG element use:

var a = document.createElementNS("http://www.w3.org/2000/svg", "svg");

Now if you compare:

var result = a instanceof SVGElement;

the result will be true.

See a working example in this JSFiddle

like image 95
helderdarocha Avatar answered Oct 15 '22 05:10

helderdarocha