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

Is Perl conducive to agile development?
Or perhaps better yet I should rephrase the title above and instead write: Is agile development conducive to Perl? For
Perfect birdie
This morning I had the perfect birdie. There was not the slightest hesitation in my mind. Three shots in a
Sunny days ahead
Looks like we've got some ideal golfing weather ahead, and I'm definitely going to take advantage of this fantastic
Offering advice
The problem with offering your opponent advice on the golf course is that if it helps then he beats you
Farrah Fawcett
I cannot believe that she died today.As a teenager I had the biggest crush on her and that poster of