Question
How can you use Javascript to accomplish the following task:
When a user clicks "Hello" button, how do you dynamically create an <h1> element and add it to a specific '<div>' element with the 'id' 'container' in the HTML document?
<button onclick="adhelo()">add hello</button>
<div id="divt"></div>
<script>
var divt= document.getElementById("divt");
function adhelo()
{
var newh1=document.createElement("h1");
newh1.textContent="hello"
divt.append(newh1);
}
</script>
No comments:
Post a Comment