javascript node Check if event target is hyperlink

javascript event target node (2)

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

If a user clicks on an items that is a hyper link, I want to check if was hyperlink and then navigate to that link if 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="">Some Link here</a>
<div class="campaign-name-sub">
   <span class="campaign-accountname">Some Text here</span>
   <span class="seprator">|</span>
   <span class="brandname">Some Text here</span>


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) {

Answer #1

I tried modifying your code and there were multiple problems with the code and corrected them.

This is the JavaScript part

var src = '<div class="camp-name"><span class="btnCampaign"><div class=""></div></span><span class="campaign-name"><a href="">Some Link here</a></span></div>';

var label = document.createElement('DIV')
label.innerHTML = src;
var topdiv = document.getElementById("test");

label.addEventListener('click', test, false);

function test(event) {
    if( === 'a') {
        var href =;
    window.location = href;

This is the HTML part of it

<div id="test">

I did this in a jsfiddle

Please let me know if the vent is captured correctly.

Answer #2

You should get it through

if( === 'a')
{; //this is the url where the anchor tag points to.