Observing and Capturing Events

Contact Us or call 1-877-932-8228
Observing and Capturing Events

Observing and Capturing Events

You are probably accustomed to using the HTML event handlers ("on" attributes) to capture events as in the demo below:

Code Sample:

AdvancedTechniques/Demos/onclick.html
---- C O D E   O M I T T E D ----

<ul>
	<li onclick="document.bgColor='red';">Red</li>
	<li onclick="document.bgColor='orange';">Orange</li>
	<li onclick="document.bgColor='green';">Green</li>
	<li onclick="document.bgColor='blue';">Blue</li>
</ul>
---- C O D E   O M I T T E D ----

It's better, however, to keep your JavaScript completely separate from your HTML. In a later lesson we'll learn more about unobtrusively attaching events to elements in the DOM to avoid using HTML event handlers.

Next