What is the most effective way to develop a html5 or js code?


For example when I want to do an event on the button click I can do it in two ways:

using the onclick attribute of html5 <button type='button' onclick='myFunction()' id='btn0'>O</button>

or by js:




There are situations that occur using two ways such as:

  <input type="checkbox" id="myCheck" onmouseover="myFunction()" onclick="alert('click event occured')">

function myFunction() {

Is this merge good? What is the right way to develop and why? What's the difference between using one or the other? if possible what are the advantages and disadvantages?

asked by anonymous 11.01.2018 / 19:49

1 answer


The correct would be to compare native functions example ...

  • onclick direct in HTML
  • onclick in javascript
  • attachEvent
  • addEventListener

jquery probably implements addEventListener and attachEvent ...

Direct onclick in HTML is somewhat used nowadays but has a normal effect.

Onclick in javascript is more common and easier to organize the scope.

AttachEvent For IE with versions smaller than 9.

AddEventListener For IE 9 and above, it is widely adopted in javascript development.

In terms of merge, I believe it is a #

In terms of performance, if there is a difference it is almost imperceptible ...

11.01.2018 / 20:08