+ 2
You cannot assign as style to innerHTML. And textContent generally is preferred over inner HTML for changing text.
https://sololearn.com/compiler-playground/WP75l6YyS494/?ref=app
+ 2
Happens "click" is reserved in JS. You need to rename the function. (answer provided by Bing)
Another issue is that you chained an assignment to the innerHTML of the element when you define x, which gives x the same value as that assigned to the innerHTML, that is "Heyo".
You probably mean to assign the element to x and use the dot notation on x in the next two statements .
Edit:
The example provided by Lisa shows a work-around without changing the function name!🤯
+ 1
Harsh https://www.w3schools.com/js/js_reserved.asp
This page on w3school.com lists some reserved words. Maybe it is not complete since it doesn't mention "click", the one we are talking about.
0
You can use onclick (see updated example above). As Lochard pointed out, you should name your function differently.
0
Harsh You can simply change the function name to anything that is not a reserved word and it will work.
You can also add the assignment to the innerHTML as a separate statement. It will also work.
https://sololearn.com/compiler-playground/W5RBXm0JiWLF/?ref=app