Home » Javascript » How to assign keydown event on an <a> tag inside <div> [on hold]

How to assign keydown event on an <a> tag inside <div> [on hold]

Posted by: admin June 30, 2018 Leave a comment

Questions:

I want to assign a keydown-event on an tag inside a . The code I have is following:

<div id="hreftest" class="maillink-wrapper">
     <a class="maillink" id="oneMessageLinkId_¤{test}" href="¤{openMailLink}" title="¤{subject}">¤{subject}</a>
</div>

And I’m doing the following script, to assign a keydown event on the link.

$("#hreftest a").keydown(function(f) {
    var d = $(f.target);
    switch(f.keyCode){
        case 13:
            window.location = $("a.maillink", d).attr("href");
            f.preventDefault();
            break;
    }
});

I have the same Javascript for many other tags, but for some reason this one is not working. I’m guessing it has something to do with the first line (“hreftest a”), but i’m not sure.

Any help appreciated!

Answers: