In the below code I have made up a property called 'foo' in the html button element. I want to be able to access that someway in the javascript function being called by 'onclick'
What I actually get if I try to call it in the same way as I would call the ID is 'undefined'
Or maybe there is some other way to send some data to the function that is not in the ID or value.
Here is a JS fiddle to demonstrate
https://jsfiddle.net/ftpeyrux/1/
function assignAllClick(button) {
document.write('This is "foo": ' + button.foo + '<br>and this is "ID": ' + button.id);
}
<button type="button" id="1" onclick="assignAllClick(this)" value="2" foo="test">Test</button>