Issue
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?
Solution
For this, always go for .addEventListener()
instead of onclick
. onclick
is not recommended for executing an action in JS.
MDN (Mozilla Developer Network)
also states that .addEventListener
must be used instead of onclick
.
For the button, it doesn’t affect the overall meaning and work of it. A button doesn’t cause a change when inside a p
tag.
Answered By – DYNAMICMORTAL
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0