Introducing 140 char (or less) JavaScript programs

Today I got tired of seeing yet another onclick="obtrusivejavascript()" 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!

Tags: , , ,

Leave a Comment

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

Comments

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

    http://identi.ca/notice/110038

    135 characters.

  2. Here’s mine. Death to inline styles…

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

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

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

  4. I’ve got one – Don’t use font tags… they’re evil

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

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

    Different for different pages….