In short, I want to do
<a href="javascript:edit(this, 123)">Edit thing</a>
instead of
<a href="javascript:;" onclick="edit(this, 123)">Edit thing</a>
where this would be the <a />, and 123 is an id. Why? It’s much cleaner. Is there any way?
How about we keep things semantic?
<button type="button" id="edit"> Edit this </button>and then add some javascript somewhere
You’ll have issues with
addEventListenerin legacy browsers. Feel free to use flow to fixaddEventListenerI also recommend you read about
And choose one of those two techniques.
Also please don’t hard code id’s into your functions like that. Your
editbutton should know what it’s editing by relative position in the DOM. it should be easy to find the semantic id that is on the correct element by a simple bit of DOM traversal.