score:1
Accepted answer
Since you're creating the drop down in the HTML, you don't need to append anything using D3.
Thus, drop this:
var select = d3.select('#opts')
.append('select')
.on('change',function() { update(this.value) });
And simply add an event listener to the dropdown:
d3.select("#opts").on("change", function() {
//code here
});
Here is a demo:
d3.select("#opts").on("change", function() {
console.log(this.value)
});
<script src="https://d3js.org/d3.v4.min.js"></script>
<select id="opts">
<option>Please select</option>
<option value="ds1">1</option>
<option value="ds2">2</option>
<option value="ds3">3</option>
</select>
Source: stackoverflow.com
Related Query
- Swap a D3.js created drop down menu into a HTML created drop down menu
- Adding drop down menu using d3.js
- Drop down menu over d3 SVG
- D3 How to update the chart after selection from drop down menu with new data
- How to create a drop down in a HTML table and d3 bar chart
- D3 simple drop down menu on click
- Making a drop down menu from csv data in JS
- Finding the user selected option(s) from a `multiple` drop down menu using d3?
- redraw d3 map according to drop down menu selection
- D3: set bar colors according to property selected from drop down menu
- d3.js drop down menu on click
- Reload data from a drop down box created by script without having to delete the element and create another one
- Adding a drop down menu in the force-layout (d3.js)
- D3 Connecting different data to 2 drop down menu
- Draw new graph on selection of new variable from drop down menu and/or radio button change
- D3: Referencing Drop Down Menu Selection
- D3 How to change dataset based on drop down box selection
- putting the country on drop down list using d3 via csv file
- How to update elements of an HTML that the elements are created using data from a CSV file?
- How can I set the position of a drop down list with D3.js?
- Transforming D3 code into Vue3 - cells not being added to rows but into HTML
- Unique pairs from data in a drop down select list using d3.js?
- Drop down button to filter a d3.js graph
- How to export multiple html tables and multiple d3 generated graphs into a single pdf
- Adding event listeners into dynamically created elements
- Right-justifying an HTML table created in D3
- How to include two htmls into another html using jQuery
- Putting HTML Table into ToolTip in D3.js
- Place svg image created by d3.js before a HTML node
- d3js drag a text from html DOM and add it to SVG on drop
More Query from same tag
- d3.js Box Plot Positioning Issue with box.js
- What is the alternative of '.orient()' in the new D3 API?
- How do I stop an error when I have multiple roots supplied via MySQL in D3.js?
- D3 select: submit form dynamically?
- Trying to return multiple data only once
- how to pass variables to event listener method in d3
- append d3 text to existing html div
- Axis Range and Domain issue on bar graph using D3
- D3 js line chart shows dot on mouse over and mouse out
- Overflow a circle outside the bounds
- d3.js graph to plot binary data
- D3 trouble parsing CSV file
- D3 time range drops the first month
- D3.js how to get the position/offset of x and y axis
- D3 - Reading from .json and attempting to plot points - nothing displayed
- d3.js width of graph
- Add line in svg using d3
- How to remove svg inside a div
- using d3.queue to wait for AJAX response
- List of d3 symbols available to us
- Clipping transformed text in an SVG
- Resize Line Graph in D3 based on Window size
- Adding Multiple shaped nodes to a force directed network diagram in d3v4
- D3.js: Import file changing with a slider
- pie chart d3.js
- Angular nvD3 Stacked Area Chart Data Series Format
- d3.js external json file
- Can't add an axis in d3.js
- my tooltip in d3 won't show up in the right place
- d3 pie charts innerRadius and outerRadius acting funky