Easy as Pie - Unobtrusive Javascript

Go back to Notes from Phazm

Click on the links below to get an alert.

]] HTML:
<div id="mylinks">
<a href="mypage.html" title="Go to my page">My Page</a> | <a href="yourpage.html" title="Go to your page">Your Page</a>
</div>
]] Javascript (without comments):
function unobtrusifier() {
	if(document.getElementById('mylinks')) {
		var links = document.getElementById('mylinks').getElementsByTagName('a');
		linklength = links.length;
		for(var i=0;i<linklength;i++) {
			links[i].onclick = function() { alert(this.title); return false; };
		};		
	};
};
]] domFunction:
var unobtrusifier = new domFunction(unobtrusifier, { 'bottom' : 'id'});