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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -