I'm experiencing an issue with removing / appending elements - which then lose their event handlers. So - the element gets cloned and appended on mousenter (which keeps all event handlers). I then use .detach() to remove the original to stop duplication, which as I understand, is supposed to keep the event listeners, but that's not what I'm seeing.
$("#containerSVG").on("mouseenter", "g", function(e){
$(this).clone(true).appendTo("#containerSVG");
$(this).detach();
});
$("#containerSVG").on("mouseleave", "g", function(){
console.log("mouse leave triggered");
});
Here's a fiddle https://jsfiddle.net/6m54ttLe/6/ that shows the issue. If I remove the detach() then the mouseleave is triggered fine, when using detach() it is not triggered at all.
All suggestions much appreciated!
Update The reason I need to use clone() and not just appendTo() is because IE and EDGE lose the event handlers completely (even though Chrome and other decent browsers do not). Here's another post that discusses the same issue. I am not using d3 (and don't have time to learn it for this project) so the solutions they talk about are not applicable SVG element loses event handlers if moved around the DOM
Update 2 I still haven't found a solution to this issue. Would love to find one! However I have found a workaround by having each path in a separate SVG with a div instead of <g> and then I can use css z-index to bring the hovered one to the front. Just thought I'd add that in case anyone else has a similar issue.