I am currently working on implementing a navigation system using a UL HTML Element.
Here's the code I have so far:
let htmlUL = <HTMLElement>document.getElementById('autocomplete_ul_' + this.name);
if (arg.keyCode == 40) { // down arrow
if (this.arrowPosition < htmlUL.childNodes.length)
this.arrowPosition++;
console.log(htmlUL.childNodes[this.arrowPosition]);
} else if (arg.keyCode == 38) { //up arrow
if (this.arrowPosition >= 2)
this.arrowPosition--;
console.log(htmlUL.childNodes[this.arrowPosition]);
}
After testing, I can see the correct data in the console when I press UP and DOWN arrows.
However, I am having trouble with
htmlUL.childNodes[this.arrowPosition].focus()
:
Property 'focus' does not exist on type 'Node'
Does anyone know how to focus on an element within childNodes? Any help would be greatly appreciated. Thanks!