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
Source: stackoverflow.com
Related Query
- D3.js Right click opens popup but does not affect the source svg when pop up closed
- IE11 does not accept SVG height and width when using D3
- Does the click event mutate the source json in this D3 example?
- When i click on the marker, the pop up doesn't appear. I get the following error
- the data is changed, but reloading does not fetch new data, D3
- Why does this code work for counting one item in a list but not the others?
- d3.js node translation does not work when changed the node to image
- "Property does not exist on type {}" error when using anonymous function with D3 SVG Symbol
- d3.create() returns an element with .node(), but does not display in the browser
- d3 svg zoom does not work when neighbouring element exists
- D3.extent() does not give the right range
- Sometimes svg chart doesn't fit in the container but it works when screen refresh
- Why animated d3 svg line is not synchronized with the axis shift in IE9 but synchronized in IE11 and Chrome?
- Why the maximum variable take the d3.max() value but the minimum one d3.min() does not work properly?
- The nested in foreignobject svg does not appear
- Change xlink:href link of svg image when image does not exits in D3js?
- Why does D3 not insert elements inside the selected element, when using data().enter()?
- D3.js: Text labels dissapear when I click on the second svg element
- .on("drag", function()) and .on("contextmenu", function()) does not work when used on the same code
- Why does my d3 visualization render in the console but not in the browser?
- ("svg:rect") element does not appear on the screen when run
- SVG does not show up on Firefox but does on Chrome
- Is there a javascript command for 'only run when the mouse is over but stop when its not over'
- How does text on SVG not update but text on a div does?
- Pattern not rendering when using group element (g) in d3, but rendering when made as an individual SVG
- Why does my JSON update for one API but not the other?
- Why does the text not appear inside the svg rects
- D3.js graph does not appear when source is saved in file
- In my d3 chart, Zoom selection disappears when I change the brush and click on not selected range
- JavaScript callback function seems to work, but does not draw the data
More Query from same tag
- How to parse a date like '2009-09-13' in D3.JS or moment
- Fix the x-axis of D3 JS and add dotted lines to the y-axis and x-axis
- How to rotate the text labels for the x Axis of a nvd3.js line chart
- Calling an Angular service in d3.queue - defer
- Display missing ticks on y axis
- dc-js line chart showing extra filled line at average change
- How to drag and rotate orthographic map (globe) using d3.js
- D3.js Draw Circle between dash
- How do I draw a percentage from baseline?
- ReferenceError- crossfilter is not defined
- d3 v4 - have value on left side of single horizontal bar chart
- How can I remove non-integer ticks while zooming in with D3.js?
- Centering an HTML div overlay on an SVG chart
- d3.js tool tip on a force directed graph not displaying complete data while hovering over links
- D3.JS: How to get nodes of corresponding link (edge)
- Changing the positions of force layout d3 dynamically
- displaying charts in browser while keeping data safe
- force graph in d3.js - disappearing nodes
- How do I use D3js in Wordpress?
- Make the same curve in SVG and CANVAS
- How to get the vertically-oriented tree using d3.js with rectangular box
- SVG g hides when parent g is set to a height
- interact between two different graphs in two different browser windows in dc.js crossfilter
- d3 data reshape: properties to array
- Memory leak from repeatedly applying d3 transition
- How do I arrange all bubbles in circular manner in bubble chart with force layout?
- Styling in D3 with a loop?
- Include javascript and html code from another file
- CSS transform-origin not working for svg in safari
- Drag is not working in this simulation layout