14 ms·
Standard code for the first and third examples, for comparison: <button onclick="this.classList.toggle('clicked')"> Toggle the "clicked" class on me </button
by zagrebian 4y ago
Standard code for the first and third examples, for comparison:
<button onclick="this.classList.toggle('clicked')">
Toggle the "clicked" class on me
</button>
<div onclick="aJavascriptFunction(), setTimeout(anotherJavascriptFunction, 10000)">
Do some stuff
</div>
The second example (triggering mouseover on #foo) cannot be that easily inlined in an HTML attribute. I think you’d have to create a synthetic event and dispatch it.
- twicetwice 4y agoThird example only works if aJavascriptFunction is sync. If it's async you'd have to do <div onclick="aJavascriptFunction().then(r => setTimeout(anotherJavascriptFunction, 10000)">Do some stuff</div> but if you don't know ahead of time whether or not it's async (or don't want to have to care, like hyperscript allows), then you'd need <div onclick="(async () => { await aJavascriptFunction(); setTimeout(anotherJavascriptFunction, 10000) })()">Do some stuff</div>