+ 1
Uncaught Type error: Cannot read property 'addEventListener' of null
Please I need help, I don't understand what that mean my code : var para = document.querySelector('p) ; var rougit = function(){ Para. classlist.toogle('red'); } ; para.addEventListener('click', rougit);
8 Answers
+ 3
you missed the closing quote in the query Selector, declared variable is para but you're using Para in the function
Can you share the complete code?
If you're running this in sololearn code playground you need to wrap your js in a function that loads after the dom is loaded:
window.onload = function() {
//Your code here
};
+ 4
Ankit thank you very much ;)
+ 3
Also it should be classList and toggle instead of classlist and toogle
+ 2
The program basically correct, but there were many typing mistakes you made.
As a programmer, you should type in precise way, it would save you a lot of time used for debugging.
<!DOCTYPE html>
<html>
<head>
<title>QnA</title>
<style>
.red {
color: red;
}
</style>
</head>
<body>
<p>Click here</p>
<script>
var para = document.querySelector('p');
var rougit = function(){
para.classList.toggle('red');
};
para.addEventListener('click', rougit);
</script>
</body>
</html>
https://code.sololearn.com/WSBoEG5W4Akm/?ref=app
+ 2
CalviŐ˛ I do not see my fault?
+ 2
OK, Thanh you CalviŐ˛
0
In JS pane, you need to put your code on onload callback.
https://code.sololearn.com/WLFNbeUR0Yir/?ref=app