Difference between obtrusive and unobtrusive javascript

well actually picture well actually · Dec 5, 2011 · Viewed 31.9k times · Source

What is the difference between obtrusive and unobtrusive javascript - in plain english. Brevity is appreciated. Short examples are also appreciated.

Answer

Joe picture Joe · Dec 5, 2011

No javascript in the markup is unobtrusive:

Obtrusive:

<div onclick="alert('obstrusive')">Information</div>

Unobtrusive:

<div id="informationHeader">Information</div>
window.informationHeader.addEventListener('click', (e) => alert('unobstrusive'))