I have created a force directed graph using D3 and displayed the id of the nodes in a normal div. I need to highlight the node whose id has been clicked in the div. I have s
When you write:
…and using normal javascript tried to click it…
what do you mean?
If you mean that you wrote code like:
mySVGElement.click();
then that is your problem. Not all DOM elements have a click() method like a or may. Instead, you need to simulate and fire your own click event:
function simulateClick(elementToClick){
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var canceled = !elementToClick.dispatchEvent(evt);
return canceled; //Indicate if `preventDefault` was called during handling
}