Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  52] [ 5]  / answers: 1 / hits: 84404  / 11 Years ago, wed, march 27, 2013, 12:00:00

I have a large div inside there which are smaller divs, achor tags and other elements.
Each large div in my program is bound to mousedown event and inside the onMouseDown handler, I basically check the event.target.



If a user clicks on an items that is a hyper link, I want to check if event.target was hyperlink and then navigate to that link if event.target was a hyperlink. How can that be done?



Here's the structure of the divsa and elements.



<div class=camp-name>
<span class=btnCampaign><div class=></div></span>
<span class=campaign-name>
<a href=http://www.google.com>Some Link here</a>
</span>
</div>
<div class=campaign-name-sub>
<span class=campaign-accountname>Some Text here</span>
<span class=seprator>|</span>
<span class=brandname>Some Text here</span>
</div>


JS



var label = label.createElement(DIV);
label.innerHMTL = src //src is the above html that is seen here
Plugin.addEventListener(label, mousedown, params.onMouseDown);


Plugin.onMouseDown() = function(event) {
var target = (event.currentTarget) ? event.currentTarget : event.srcElement;
if (target.tagName.toLowerCase() === a && target !== undefined) {
console.log(target.href);
Plugin.stopPropagation(event);
}
};

More From » html

 Answers
25

You should get it through



if(event.target.tagName.toLowerCase() === 'a')
{
event.target.href; //this is the url where the anchor tag points to.
}

[#79304] Tuesday, March 26, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tatyanna

Total Points: 552
Total Questions: 96
Total Answers: 96

Location: Cook Islands
Member since Thu, May 21, 2020
4 Years ago
;