开发者

how can I know that onmousedown event is set for a link?

开发者 https://www.devze.com 2022-12-23 07:36 出处:网络
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?

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

开发者_如何学C

Alex


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.push(anchors[i]);
    }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消