JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<svg width="100" height="100"><rect class="node" fill="red" width="50" height="50" x="25" y="25"></rect></svg>
<div class="node" style="border:1px solid red; height:20px;width:20px;"></div>
JavaScript
// adapted from https://github.com/jquery/jquery/blob/d837f119c3729565103005d5d7fa89e1dd8110cb/src/attributes/classes.js
var rclass = /[\t\r\n\f]/g;
hasClassSVGCompatible = function( selector ) {
var className = " " + selector + " ",
i = 0,
l = this.length,
compareName;
for ( ; i < l; i++ ) {
compareName = this[i].className.baseVal || this[i].className;
if ( this[i].nodeType === 1 && (" " + compareName + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
return true;
}
}
return false;
}
$(".node").hover(function(evt){
console.log("$.attr: " + $(this).attr("class")); //returns "node"
console.log("$.hasClass: "+ $(this).hasClass('node')); //returns false
console.log("hacked $.hasClass: "+hasClassSVGCompatible.call($(this), 'node'));
console.log("d3.classed: "+ d3.select(this).classed("node"));
}, function(){console.log("Done");});