views:

40

answers:

2

Hi guys,

I want to parse an html document after it has loaded and discover all the links that the onmousedown event is set for them - how do I do that?

Thanks

Alex

A: 

I don't think you can.

If it's one of your script that sets the onmousedown event, you can modify it so it adds an attribute to the dom elements you set an event handler, so you can test that attribute later.

David V.
A: 

While you can't do this directly, you can create an array of elements with the onmousedown property by using a couple of inbuilt functions.

// get all anchor tags
var anchors = document.getElementsByTagName('a');
// empty array to store matches in
var matches = [];

// loop through all anchors
for (var i = 0, len = anchors.length; i < length; i++)
{
    // if there is an onmousedown function, add it to the array
    if (typeof anchors[i].onmousedown == 'function')
    {
         matches[matches.length] = anchors[i];
    }
}

Note I haven't tested this so there is almost certainly a typo in it.

slightlymore