How can I check the type of an svg object in JavaScript or jQuery?
I want to check whether a tag is of type SVGAnimatedString.
When I output the object to the console it outputs the following:
console.log(this.href);
SVGAnimatedString // is an object and can be expanded
In my code I try to check whether it is a SVG object but the check does not work.
if (this.href == 'SVGAnimatedString'){ //this check does not work
//it s an svg object
var url = this.href.animVal
}
else{
var url = this.href; //get the href from the <a> element
}
How do I correctly check whether it is a SVGAnimatedString object?
You should not compare the types using
==. You need to useinstanceof. You can do this way:The
SVGAnimatedStringhas less browser support. Keep that in mind. 🙂