[thelist] [Easy as Pie] Unobtrusive Javascript

Stephen Rider evolt_org at striderweb.com
Wed Dec 19 10:06:31 CST 2007

Kind of subsidiary to the topic, but, looking at this code:

if(document.getElementById('mylinks')) {
	var links = document.getElementById('mylinks').getElementsByTagName 

Am I correct in believing that that can be written as:

if( var links = document.getElementById 
('mylinks').getElementsByTagName('a') ) {


Then, changin this:

linklength = links.length;
for(var i=0;i<linklength;i++) {

to this:

for(var i=0;i<links.length;i++) {

We can thus reduce your already short 9-line function to a mere 7  
lines.  :)

On Dec 16, 2007, at 8:25 PM, Jon Hughes wrote:

> Hey list,
> I remember when I first joined this list about a year to a year and a
> half ago, I didn't know anything about JavaScript, my browser
> compatibility skills were sub-par and my markup was bitter tag-soup.
> Thanks to this list, I am now (in my own very humble opinion) able to
> spread the knowledge I gathered from this list to others.
> I recently posted the first in a continuing series of DIY posts, which
> is entitled, "Easy as Pie - Unobtrusive JavaScript"
> http://www.phazm.com/notes/javascript/easy-as-pie-unobtrusive- 
> javascript/

More information about the thelist mailing list