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>


Related Query

More Query from same tag