Home > Net >  Why in typescript taps only work first tap
Why in typescript taps only work first tap

Time:12-28

My problem is when i click tap only first tap is working when i click another tap is show error

Uncaught TypeError: Cannot read properties of undefined (reading 'classList')

This my code enter image description here

So when you call

let panals = document.getElementById('panals')

It will return the first element with an id of 'panals', regardless of which panel you click on. This will be the 'John' panel. So when you click on 'Anna' and try and do

panals.getElementsByClassName('Anna')[0]

it will return undefined because panals will always be the John panel.

  • Related