Hello guys im building a library, for example i give an atribute to a html element
<a href="https://google.com" shc="27">
logout
like this one shc="27" which means when the key 27 (ESC) will be clicked on keyboard it will trigger a click on the link but for some reason it denies to click it. here is my full code:
$(document).on("keydown", function(e) {
console.log(e.which);
checkElementType(e.which);
});
function checkElementType(shortcutKey){
var element = $("[shc="+shortcutKey+"]");
var elementType = element.prop('nodeName');
switch(elementType){
case 'A':
console.log(element);
console.log('click the link');
element.trigger('click');
break;
}
}
here is the fiddle : Fiddle