Help JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Help JavaScript

textEdit.write("text") must create new paragraph with text and show it but why it doesn't? https://code.sololearn.com/W3h326EcyUrF/?ref=app

22nd Nov 2019, 6:26 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar
4 Answers
+ 3
CodeCat_ document.body no need id
23rd Nov 2019, 12:40 AM
Gordon
Gordon - avatar
+ 2
firstly you need to appendChild secondly you need window.onload because scripts in JS tab goes to <head> so at that moment there is no <body> yet https://code.sololearn.com/W6mU02g5RHia/?ref=app
23rd Nov 2019, 12:44 AM
Gordon
Gordon - avatar
+ 1
<!-- Something like this?? --> <html> <body id="bd"> </body> </html> <script> window.onload = () => { var textEdit = (function(text){ let e = document.createElement("p"); document.getElementById("bd").appendChild(e); e.appendChild(text); })(document.createTextNode("test")); } </script>
22nd Nov 2019, 7:05 PM
VOID
VOID - avatar
0
Okay, thanks u all
23rd Nov 2019, 5:48 AM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar