It doesn't work in my computer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

It doesn't work in my computer

<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <button onClick = "hello()">click me</button> <div id="demo"></div> </body> </html> <script> function hello() { var p = document.createElement("button"); var node = document.createTextNode("new"); p.appendChild(node); var div = document.getElementById("demo"); div.appendChild(p); }; </script> i have been using this code in my computer but it doesn't work

31st Jan 2018, 12:21 AM
Danilo
Danilo - avatar
5 Answers
+ 3
Your skeleton of your program is - <html> <head>...</head> <body>...</body> </html> <script>...</script> In above program <script> tag is outside body tag, it should be inside body tag, after <div>...</div>. What it should be <html> <head>...</head> <body> <!--body code here> <script>...</script> </body> </html> and copy your new edited code to Notepad, and save it with ".html" or ".htm' extension. like myprogram.htm or hello.htm and open the file in a web browser like chrome or firefox. Hope it helps.
31st Jan 2018, 12:37 AM
Uttam
Uttam - avatar
+ 3
@Oleg <script> tag can be inside either <body> tag or <head> tag. Both are valid.
31st Jan 2018, 12:40 AM
Uttam
Uttam - avatar
+ 3
@Uttam, ye i know, but i think put script in head tag it's better practice) it's just my mind)
31st Jan 2018, 12:43 AM
Oleg «0RaKlE19» Kolodka
Oleg «0RaKlE19» Kolodka - avatar
0
thanks
31st Jan 2018, 1:28 AM
Danilo
Danilo - avatar