i am trying to use my keyboard to click on a button using the id.
For some buttons i had to set the ID, which actually works. But as soon as i try to use the keyboard for the buttons where i set the id, it won't work.
I am not getting any errors and since adding the id to the element works, i am kinda confused why i cannot use the new set id later in the code.
//setting id for first button (works)
$( "a:contains('Im Verband freigeben')" ).attr('id', 'freigabe-verband');
//setting id for second button (works aswell)
$( "a:contains('Vorheriger Einsatz')" ).attr('id', 'vorheriger-einsatz');
$( document ).keydown(function(e) {
if (e.keyCode == 39) {
//works, id is available, not set by me
$("#alert_next").click();
} else if (e.keyCode == 38){
// doesn't work, but id is set
$("#freigabe-verband").click();
} else if (e.keyCode == 40){
// doesn't work, but id is set
$("#vorheriger-einsatz").click();
}
return e.returnValue;
});
Anyone know why? https://i.sstatic.net/nQtRc.png
id
, you need to delegate the event. – Ripley