An Example

Example 1

In this example, we create an html element in JavaScript.

Code:

<script>
function addStuff(){
	var btn = document.createElement("INPUT");    
	var t = document.createTextNode("CLICK ME");    
	btn.setAttribute("type", "button");
	btn.setAttribute("value", "Click This");
	btn.setAttribute("onclick", "alert('you did it!')");
	//appendChild(t);    
	//document.body.appendChild(btn);
	document.getElementById("output").appendChild(btn);
	
	var txt = document.createTextNode("This is exciting text!");
	document.getElementById("output").appendChild(txt);
}
</script>

Output: