I was previously using Graphviz 2.38.0, and the onclick attribute in DOT files was working as expected — I could add JavaScript handlers in SVG output without any issues.
However, after upgrading to Graphviz 2.40.1, the onclick functionality no longer works. I’ve tried generating SVG output, but the onclick handlers are missing from the generated elements.
I’ve reviewed the release notes and documentation but couldn’t find any official mention of this change.
Has onclick (and possibly other interactive attributes like href, target) been removed or deprecated in 2.40.1?
Is there any workaround or recommended approach for enabling interactivity in this version?
Any pointers or references would be greatly appreciated!
The workaround is to set a id or class on your elements then add some javascript to your page that selects that element e.g. using document.querySelector and adds an event listener, e.g. with element.addEventListener.
HTML onclick attributes are a bit old-timey and I think considered somewhat deprecated.
Fwiw I think the security considerations alluded to there might be overblown - I don’t think there is any security boundary being traversed here. So maybe we should add these back in. But it’s hard to tell without knowing the exact security issues that led to the removal.