Random link

 | Javascript | 0 Comments

Let's say that you want to select a random link within a certain div tag which has a given id and then jump to where that link points to. Here's a way to do that.


function random_link(id)
{
    var obj = document.getElementById(id);
    var links = obj.getElementsByTagName("a");
    var offset = Math.floor(Math.random() * links.length);
    document.location = links[offset].href;
}

Leave a comment

Recent Entries

Gale-force winds
"The true (golf) pilgrim wanders off to the outlying, the more humble and obscure courses. For it is on
Secret powers
The front nine was quite a display of supernaturally and (almost) perfectly consistent golfing gusto: Par, par, par, par,
No more winter greens
The cool, windy and grayish afternoon calls me onward. It's drizzling on my windshield but I do not care.
Champion of Scotland
I nearly cried my eyes out when I discovered that young Tommy Morris dies in the prime of his
Sticky keyboard
Up until yesterday the Del-, Ins- and Home- keys on the upper right-hand corner were sticking alot, and it's