+ 1

Is there a way to display javascript?

https://code.sololearn.com/W79JKOD5Fb2v/?ref=app This is my code. My question is whether or not it is possible to display the "name" in the code in the HTML page. Instead of it being an alert, is there a way to have it appear on the page?

24th Dec 2019, 7:56 PM
Toby Boudreaux
Toby Boudreaux - avatar
8 Respuestas
+ 1
Try this bro: window.onload = function(){ let name = window.prompt('Enter your name: '); let mainbody = document.querySelector("body"); let h1node = document.createElement("h1"); let text = document.createTextNode("hello "+name); h1node.appendChild(text); mainbody.appendChild(h1node); };
25th Dec 2019, 2:15 AM
Thống Nguyễn
Thống Nguyễn - avatar
+ 1
If you just want to have the name displayed in page, use document.write(name)
24th Dec 2019, 8:04 PM
molang
molang - avatar
+ 1
Well, I don't know much about html, but I hope this link will be helpful: https://www.w3schools.com/jsref/jsref_obj_string.asp
24th Dec 2019, 8:49 PM
molang
molang - avatar
+ 1
Thank you molang. I can work with this.
24th Dec 2019, 8:50 PM
Toby Boudreaux
Toby Boudreaux - avatar
+ 1
Thanks Thống Nguyễn ! This is exactly what I was looking for! :)
25th Dec 2019, 3:00 AM
Toby Boudreaux
Toby Boudreaux - avatar
+ 1
Toby Boudreaux please to help you!
25th Dec 2019, 3:02 AM
Thống Nguyễn
Thống Nguyễn - avatar
0
molang if I use document.write(name) Does it allow me to manipulate the text? Such as with CSS and other javascript?
24th Dec 2019, 8:35 PM
Toby Boudreaux
Toby Boudreaux - avatar