- 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

16th Jan 2020, 3:21 PM
Nor'wester 🌪️ 🇧🇩 (INACTIVE)
Nor'wester 🌪️ 🇧🇩 (INACTIVE) - avatar
4 Réponses
+ 3
Nor'wester Button should be like thus way. <button type="button" onclick="document.getElementById('id1').style.color = 'red'"> Click Me!</button>
16th Jan 2020, 3:56 PM
DishaAhuja
DishaAhuja - avatar
+ 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 ;)
16th Jan 2020, 3:58 PM
visph
visph - avatar
+ 2
visph agreed. That's may be the reason button click is beside the text.
16th Jan 2020, 4:00 PM
DishaAhuja
DishaAhuja - avatar
+ 1
Well, lesson learnt. TYPE the whole thing from now on. Thanks, it worked!
16th Jan 2020, 4:11 PM
Nor'wester 🌪️ 🇧🇩 (INACTIVE)
Nor'wester 🌪️ 🇧🇩 (INACTIVE) - avatar