Why does this eŕror occurs ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does this eŕror occurs ?

Hello can you help me ? I don't understand what's wrong, it writres "Cannot read property addEventListener of null" https://code.sololearn.com/W5TKLRB03i55/?ref=app

24th Nov 2019, 12:26 PM
salut
salut - avatar
4 Answers
+ 1
It's because t1 in the starting points to the Audio object And in the end you use the same variable to point to the rect element So change the variable name
24th Nov 2019, 1:41 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
0
Just wrap your method with a function of onload event onload = function(){ var t = document.querySelector('rect'); t.addEventListener('click', function(){ t1.play(); }); }
24th Nov 2019, 1:11 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
0
Ok thanks but now it does not read my function "t1.play is not a function"
24th Nov 2019, 1:32 PM
salut
salut - avatar
0
Thanks it works :)
24th Nov 2019, 1:45 PM
salut
salut - avatar