To access the DOM element from a d3 selection is a little tricky, and there are often better ways to achieve what you want to do. Regardless, if you have a single element selected, it will be the first and only item within the first item of a d3.selection - i.e. you need to access it like so:
var someIdDOMelement = d3.select("#someid");
An edited example of your original using this: http://jsfiddle.net/cpcj5/1/
If you have the id and specifically want to get the DOM element, I'd just go with getElementById:
var someIdDOMElement = document.getElementById("someid")
Looking at d3 documentation for binding events using on, we can see that, within the function you bind, the
this variable is the DOM element for the event which was triggered. So, when dealing with event handling in d3, you can just use
this to get the DOM element from within a bound function.
d3.select on the dom element bound to
this. This is how the original code does it: http://jsfiddle.net/cpcj5/3/
If you have any difficulties caused by this, please comment so I can address them.
You can also use selection.node() in D3:
var thisNode = d3.select("#" + id); thisNode.node().parentNode.appendChild(thisNode.node());
- Selections in D3: how to use parentNode.appendChild?
- How to save d3 selections in an array for later use D3.js?
- How to use d3 filter and update function to toggle between data selections
- how to format time on xAxis use d3.js
- How to use D3 in Node.js properly?
- How to use D3 selectAll with multiple class names
- How to access the parentNode of a selection to raise an element?
- How to properly add and use D3 Events?
- How to use an arrow marker on an SVG <line> element?
- How to use d3.min and d3.max within a d3.json command
- How do I use angularjs directives in generated d3 html?
- How to use the D3 diagonal function to draw curved lines?
- d3: How to properly chain transitions on different selections
- How to get maximum value from an array of objects to use in d3.scale.linear().domain()
- how to include use of node_modules in rollup compile
- How do I resolve "[ERR_REQUIRE_ESM]: Must use import to load ES Module" when using D3.js 7.0.0 with Next.js 11.0.1?
- How can I use d3 classed selection to have name as function
- How to use 'this' in Angular with D3?
- how to use svg file for image source in D3
- d3.js: how to use map function?
- How to use D3js on server side to generate SVG directly?
- How to use `this` and `_this` (fat arrow) using coffeescript?
- How to make a color scale in D3 JS to use in fill attribute?
- How to use SVG gradients to display varying colors relative to the size of the colored region
- How can I use d3.js to create a trend/exponential regression line?
- D3.js - how selections work - Need clarification on Mike's article
- Reusable charts in d3: how do the create and update selections work?
- How to use D3 zoom behavior with ViewBox instead of transform
- How can I use d3-scale-chromatic functions with a domain other than [0, 1]?
More Query from same tag
- Updating Force Layouts in D3v4
- D3.js append circle to the GROUP based on the JSON value
- d3.js - select force layout group not update the nodes
- D3 X-Value Mouseover Multiple Line Chart
- add data to chart using c3.js
- D3.js Rendering topoJSON in multiple charts
- Is the order of the ".on" functions important in D3?
- Placing Image in the Center of a Sunburst Chart with D3.js
- D3 force layout - How to achieve 3D look of nodes?
- d3.json asynchronous solution
- How can I use D3.js "onClick" event with an nvd3 bar when zoomed in on chart data?
- How to get a value of select with d3?
- How to assign alternative depth values only to the child nodes in d3js?
- D3.js selecting a part of data to be visualized from a large dataset
- D3.js violin plot not showing up
- How to add the data in the tooltip after the dataset switching
- Manually add an element to a selection in d3
- How to set the width of td as float number
- Multidimensional array for D3
- D3 components do not update in React
- Using str.replace() to fix clipPath case-sensitivity makes SVG file uneditable
- How to change the CSS "animation-delay" property in D3?
- D3 force layout differences between v3 and v4 when using mutliple connected components
- How to display d3 elements on a gridster box?
- Updating array throws error in d3
- D3 Hover Over Changes When Data Changes
- d3.js - Reload chart
- d3: my code will create 1 chart but not 2
- How can I write a piece of text over my rectangles in D3?
- Extra legend present