+ 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?
8 Antworten
+ 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);
};
+ 1
If you just want to have the name displayed in page, use document.write(name)
+ 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
+ 1
Thank you molang. I can work with this.
+ 1
Thanks Thống Nguyễn !
This is exactly what I was looking for!
:)
+ 1
Toby Boudreaux please to help you!
0
molang if I use document.write(name)
Does it allow me to manipulate the text? Such as with CSS and other javascript?