JSFiddle - React, Tailwind, and code Playground

by Emily Humphrey

HTML

<a href="#0" data-push-link>Push link</a>

JavaScript

function PushLink(element){
    this.element = element;
    this.link = this.element.attr("href");
    this.keyPress = "not pressed";
    this.alert = function(){
        this.keyHit();
        var key = this.keyPress;
        alert(this.link+" "+key);
    };
    this.keyHit = function(){
        var keyPress;
        this.element.keydown(function(e){
            keyPress = e.which;
            alert(keyPress);
        });
        if(keyPress != undefined){
            this.keyPress = keyPress;
        }
    };
}

$("a[data-push-link]").each(function(){
    var pushLink = new PushLink($(this));
    pushLink.element.on("click", function(){
        pushLink.keyHit();
        pushLink.alert();
    });
});