How to automatically create a div tag in javascript?
I want to automatically create a div tag and insert some text in it when a certain button is pressed
can anyone please tell me the html codes
document.createElement(“div”); <==makes the div section
so assign it to a variable:
var divNode = document.createElement(“div”);
Then to add content inside of that div tag, use the javascript innerhtml on the divNode (or whatever you want to call it):
divNode.innerHTML = ”
The text you want here
“;
document.body.appendChild(divNode);
Leave a Reply
You must be logged in to post a comment.