0

help me to find the error in my code...

<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>What JavaScript can Do </h1> <p id="demo">JavaScript can change the html content. </p> <button type="button" onclick="document.getElementById('demo').innerHTML = 'hello i m javaScrip'">Click Me</button> </body> </html>

16th Jul 2016, 5:34 AM
sorath Peetamber
sorath Peetamber - avatar
9 Respostas
+ 4
You have to use the same quotation marks, so it should be: "hello i m JavaScrip"
16th Jul 2016, 5:57 AM
ThreeG
ThreeG - avatar
+ 1
Replace button tag with this one : <button type="button" onclick="document.getElementById('demo').innerHTML='hello i m javaScrip'">Click Me</button> You missed 't' at documen and missed ' at innerHTML function string value
16th Jul 2016, 2:31 PM
Ayub Narwidian Adiputra
Ayub Narwidian Adiputra - avatar
+ 1
Hi @sorath, don't change double quote, try to add single quote before it, you miss the single quote closing, or try this on, it worked: <button type="button" onclick="document.getElementById('demo').innerHTML='hello i m javaScrip'">Click Me</button>
16th Jul 2016, 2:53 PM
Ayub Narwidian Adiputra
Ayub Narwidian Adiputra - avatar
+ 1
It works well in my code playground. All you need to do is copy your whole line of coding and paste it on HTML section in code playground (but if there's coding in that section you must clear it first). Then click run. I think it didn't run because you paste it in JS section. This way doesn't work since your coding combines HTML and JavaScript together in a same page. Hope that answers your question. ☺
17th Jul 2016, 6:53 AM
Azwan Abdullah
Azwan Abdullah - avatar
0
I think it should be 'document.getElement'
16th Jul 2016, 6:40 AM
Abhas Mishra
Abhas Mishra - avatar
0
@Three G I have changed the double quotes but still shows the error.
16th Jul 2016, 2:26 PM
sorath Peetamber
sorath Peetamber - avatar
0
<button type="button" onclick="document.getElementById('demo').innerHTML='hello I\'m JavaScript\'s'">
26th Jul 2016, 6:12 PM
Abhishek Korgaonkar
Abhishek Korgaonkar - avatar
- 2
boa tarde
16th Jul 2016, 7:03 PM
Lourdes Tavare Lourdes Tavares
Lourdes Tavare Lourdes Tavares - avatar
- 3
I think you can write javasript in <head> eg:<head> <javascript> onclick function(){ document.ElementById("demo").innerHTML="......" } </javascrip> </head>
16th Jul 2016, 2:16 PM
gulily