score:3

Accepted answer

First of all I set the id correspondent to each element by :

.attr("id", function(d) { return "id_" + parseInt(d.x)+"_"+parseInt(d.y)+"_"+Math.floor((Math.random()*100)+1) })

Then in the function contextmenu I get the id by :

function contextmenu() {
var position = d3.mouse(this);
var node= d3.select(this).attr("id");   
d3.select('#my_custom_menu')
  .style('position', 'absolute')
  .style('left', position[0]+200 + "px")
  .style('top', position[1] + "px")
  .style('display', 'block');

d3.event.preventDefault();
document.getElementById('nodeId').value= node

}

Then in the function closepop

function closepop(){
 d3.select('#my_custom_menu')
 .style('display', 'none');
 var selectN=document.getElementById('nodeId').value;
d3.select('#'+selectN)
.style('fill', 'green');

}

score:0

Try this instead...

var selectNode =  document.getElementById('nodeId');
selectNode.style.setProperty("fill", "green", "");

score:3

In close up function selectNode fetch only the string. Can't call style method ,

Try this code:

Fiddle:

var selectNode =  document.getElementById('cir');
     selectNode.style.fill="red";

For solving your problem , select node as a global variable,then access as your same code.

Fiddle


Related Query

More Query from same tag