Skip to content

ara pehlivanian

Web Standards, Web Culture, Web Everything.™

Introducing 140 char (or less) JavaScript programs

Today I got tired of seeing yet another onclick="myjavascriptsucks()" in HTML so I wrote a little program in protest. What I wanted to do though was to post the program to Twitter which has a 140 character limit so it was mildly challenging. Here it is:

Fully expanded:

var elems = document.getElementsByTagName("*");
for (var i = 0; elems[i]; i += 1) {
    if (elems[i].getAttribute("onclick")) {
        elems[i].onclick = function () {
            alert("FAIL!");
        }
    }
}

Compressed for Twitter:

var x=document.getElementsByTagName("*");for (var i=0;x[i];i++){if (x[i].getAttribute("onclick")){x[i].onclick=function(){alert("FAIL!");}}}

I invite you to continue the trend. Write 140 character (or less) JavaScript programs and post them to Twitter then post a link here in the comments. If the trend grows, I’ll build a small site to host the activity.

I’ll go first!

Sphere: Related Content

Buy my book

The Art & Science of JavaScript / SitePoint
The Art & Science of JavaScript

Advertisement

Firebug - Web Development Evolved

Advertisement

6 Comments

  1. Gravatar for Ara PehlivanianAra Pehlivanian says:

    http://twitter.com/ara_p/statuses/861969980

  2. Gravatar for Sarven CapadisliSarven Capadisli says:

    Since I no longer use twitter, I’ve posted mine at identi.ca.

    http://identi.ca/notice/110038

    135 characters.

  3. Gravatar for Nathan SmithNathan Smith says:

    Here’s mine. Death to inline styles…

    http://twitter.com/nathansmith/statuses/862131931

  4. Gravatar for Dave LoweDave Lowe says:

    Here’s my contribution: a mild alteration for unaccessible images.

    http://twitter.com/davelowe/statuses/862141134

  5. Gravatar for Daniel MarinoDaniel Marino says:

    I’ve got one - Don’t use font tags… they’re evil

    http://twitter.com/starzonmyarmz/statuses/862153947

  6. Gravatar for thatjsguythatjsguy says:

    http://twitter.com/thatjsguy/statuses/862229507

    Different for different pages….

Leave a comment

Note: First time comments will be held for moderation as an added anti-spam measure.

Skip to navigation

More stuff by Ara elsewhere on the web

    Snook Approved!

    © 2005-2008, Ara Pehlivanian.

    Stock photography courtesy stock.xchng. This site uses Akismet to catch spam (55,294 caught since May 2006) is hosted by DreamHost and powered by WordPress.