javascript - Trigger event on link wont work -
hello guys im building library, example give atribute html element
<a href="https://google.com" shc="27"> logout
1 shc="27" means when key 27 (esc) clicked on keyboard trigger click on link reason denies click it. here 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 link'); element.trigger('click'); break; } }
here fiddle : fiddle
change element.trigger('click');
element[0].click()
Comments
Post a Comment