Bootcamp sample html file suggests a button written like this:
<p><a class="btn btn-primary btn-lg" onclick="run_update()" role="button">Button</a></p>
Though, I’ve written button always like this
<button class="btn btn-primary" onclick="run_update()">Button</button>
They seems identical and functions similarly. I’m wondering are they any different or will they impact performance everso slighly?
For this, always go for
.addEventListener() instead of
onclick is not recommended for executing an action in JS.
MDN (Mozilla Developer Network)
also states that
.addEventListener must be used instead of
For the button, it doesn’t affect the overall meaning and work of it. A button doesn’t cause a change when inside a
Answered By – DYNAMICMORTAL