score:0
Accepted answer
You can use, event as an object to be passed and access the value as (in order to get the id),
event.target.getAttribute('id')
You need to modify the button code as,
<button id="starting" onclick="update_view(event)">Starting players</button>
and in function,
update_view(event){....}
and access the id using the target object as mentioned in the first code.
Update:-
function update_view(event) {
d3.csv("../../data/appearances.csv", function (data) {
data.sort(function (b, a) {
if (event.target.getAttribute('id') === 'starting') {
return a.starting - b.starting;
}
else if (event.target.getAttribute('id') === 'substitution') {
return a.substitution - b.substitution;
}
})
})
};
<button id="starting" onclick="update_view(event)">Starting players</button>
<button id="substitution" onclick="update_view(event)">Substitution players</button>
Source: stackoverflow.com
Related Query
- Pass value from button in HTML to function in Javascript
- D3 JavaScript return data value plus variable from anonymous function
- How to pass input file parameter from html page to a Javascript
- Pass JSArray from HTML to Javascript
- How to call javascript function from D3 button
- Unable to pass javascript literal from array values to D3 function
- Getting same value from javascript function
- Javascript - How to pass original object to callback function
- Call JavaScript function from SVG file
- Blazor, get Input value from Javascript created DOM Element
- Pass variable from Express to Client JavaScript
- Selecting a specific value from an array of objects in javascript
- When selecting an option from the dropdown selection box created via d3.js the value sent to the button becomes undefined
- Saving value from HTML form to use in d3
- How to load a csv file from static in django into javascript function
- dc.js - reduce function selected from radio button
- Use elements from a predefined list as variables on a JavaScript function
- d3.js code from javascript console to html page
- Javascript button onclick event to call function inside function in module
- How to change the tick value in d3, javascript from "1900" to "January"?
- How do I send javascript parameters to DOM elements in from HTML table cells?
- How to pass a value to line generation function in D3
- Node.js : how to pass JS variable's value from script to terminal?
- Javascript - pass THIS in function doesnt work
- DC.JS Pie Chart + Select Deslect from external JavaScript function
- javascript d3 get the biggest value from a multi-nested array/object dataset
- d3js: How to pass button id to onclick callback function
- D3JS: is it possible to pass a function which retrieves a value to "transform, translate" property?
- Include javascript and html code from another file
- load JSON from rails controller to d3 .defer() function within javascript file
More Query from same tag
- How to control the number of tick values in a graph with d3js
- Using public variables and interfaces in external libraries when using Typescript
- Identify given array is a d3 selection
- Adding hover effect in d3 word cloud
- How to set the image size in Vis.js network graph
- d3.js bubble chart, mousover and mouseout events only working first time
- D3.js Tooltip with filled area graph
- 'd3.nest()' cannot read property of undefined
- How to get a circle position in a g element in SVG using D3.js
- d3 stack on data without header
- Hide root node and edges in D3 v4 Tree Diagram
- Parent child JSON from CSV using Python sunburst
- D3.js Transition issue
- Show texts on Mouseover on links
- Highlight a set of nodes and their relation between them
- Trying to understand how D3 .data key function works
- Group shapes/counties together by a list of attributes with D3.js
- Multi level pie chart in d3
- My d3.js Scales are not working
- How can we load color from a sequential scale into a map in D3 v5?
- How to increase time to read d3.json data for large data set and slow networks?
- Object property is null, but the value entered is not. How do i insert the value properly?
- Path and graph elements not displaying in D3
- How to update multiple pie charts in one page in D3?
- callback function inside of controller finishing after ng-options
- Passing data to d3 after preprocessing in a Flask app
- I can't get d3 transition to work with requestAnimationFrame
- Filter with datum in D3js?
- Bootstrap and D3 problems
- How to append <g> element after grouping my circles in D3?