0
AddEventListener ошибка при вызове из класса
Не понимаю почему выскакивает ошибка в JS при вызове функции. uncaught typeerror: cannot read properties of null (reading 'addeventlistener')
2 Respuestas
+ 1
/*
Create Abb object inside a "load" event handler. Scripts are pushed into <head> block when running in SoloLearn mobile app, the DOM isn't yet properly initialized when script is executed.
querySelector() accepts a selector, so pass "#ddd" (a valid ID selector) rather than just "ddd".
Abb::ccc() doesn't need any argument, you can get rid of that, and adjust the call to Abb::ccc() just like this
h.ccc(); // no argument passed
You can use classList.toggle("iii") instead of manually adding or removing CSS class
https://www.w3schools.com/jsref/prop_element_classlist.asp
*/
window.onload = function()
{
var h = new Abb('#ddd');
h.ccc();
}
P.S. Next time please, attach your code bit link in post Description for better view of the problem.
* Added for context clarity (found in OP's profile)
https://code.sololearn.com/WXqrmUUNMbc7/?ref=app
+ 1
Thank you very much, I learned interesting information.