- 1
Why doesn't this code work?
It worked fine at W3.school. I got this from there, hoping to practice, and..... nothing. <!DOCTYPE html> <html> <body> <h1 id="id1">My Heading 1</h1> <button type="button" onclick="document.getElementById('id1').style.color = 'red'"> Click Me!</button> </body> </html> https://code.sololearn.com/W4N3JCH7ej8f/?ref=app
4 Answers
+ 3
Nor'wester
Button should be like thus way.
<button type="button"
onclick="document.getElementById('id1').style.color = 'red'">
Click Me!</button>
+ 3
You probably have copy pasted whole code wich contains non-breaking-spaces... open it with web sololearn code playground (open the link in a browser rather than in the app) will red hilight those html unsupported white spaces inside tag, and replace them with normal white spaces: it should now work ;)
+ 2
visph agreed. That's may be the reason button click is beside the text.
+ 1
Well, lesson learnt. TYPE the whole thing from now on. Thanks, it worked!