The following code snippet is from jquery.graphviz.svg There is an svg image inside a div called "graph". When the div content is replaced with another svg the click event registered here is lost.
$(document).ready(function(){
$("#graph").graphviz({
url: "demo.svg",
ready: function() {
var gv = this
gv.nodes().click(function () {
var $set = $()
$set.push(this)
$set = $set.add(gv.linkedFrom(this, true))
$set = $set.add(gv.linkedTo(this, true))
gv.highlight($set, true)
gv.bringToFront($set)
})
$(document).keydown(function (evt) {
if (evt.keyCode == 27) {
gv.highlight()
}
})
}
});
});
I tried changing "gv.nodes().click(function () {" to the following without luck
$(document).on("click",gv.nodes(),(function () {...}
Is there a different way to solve this?
UPDATE:
With a mutation callback, an alert works within the callback, but re-registering the click event is not working:
var gv = $('#graph').data('graphviz.svg')
gv.nodes().off().on('click',function () {alert('entered doc clck')