I have a set of SVG elements with the classes node
and link
. My program should detect whether an element has the node
class or the l
As Bergi pointed out in comments, jQuery silently fails on SVG elements on account of className
returning an SVGAnimatedString
object instead of a normal DOMString
.
See this JSFiddle for a comparison.
I was tempted to submit a pull request on this, but did a quick project search, and apparently the jQuery project stance on SVG issues is wontfix: https://github.com/jquery/jquery/pull/1511
If you're using D3, you could use d3.select(this).classed('node')
. Note that D3 correctly returns for both HTML elements and SVG elements.