Reputation: 53
It's just a question. Sometimes when I use d3.js after I create object then I need to do some event or get some specific attribute by jQuery. The jQuery code just sometimes doesn't work but some other times it works. Did any one ever been this before?
Upvotes: 0
Views: 706
Reputation: 1563
One thing I encountered is that jQuery's addClass
, removeClass
, toggleClass
doesn't work on SVG (d3.js creates SVG elements), that's because The HTML and SVG DOM extensions have different definitions for "className". More details in this article.
Another thing is event handler, for example, when I bind a jQuery event handler on a selection element, I have to get the data on the SVG element by using this.__data__
. Although it might be easier to just use d3.js event handler combined with dispatch
event, rebind
, etc. Besides, manually triggering event in d3 can be quite different than jQuery, such as:
var event = document.createEvent('Event');
event.initEvent('change', true, true);
d3.select("#element").node().dispatchEvent(event);
Upvotes: 1