NextIndexPrevious

Programs in JavaScript

18. createElement and createTextNode example.

<html>
<head>
<style>
#msg{
	width:200px;
	height:200px;
	background-color:#FC6;
}
</style>
<script type="text/javascript">
	function fun1()
	{
		var d = document.getElementById("msg");
		var e = document.createElement("p");
		var txt = document.createTextNode("Welcome to all");
		
		e.appendChild(txt);
		d.appendChild(e);
	}
		
</script>
</head>

<body>
<input type="button" value="Add" onclick="fun1()" />
<div id="msg">
</div>
</body>
</html>

Output :





Father of JavaScript


Brendan Eich

Brendan Eich

Born: 1961, Pennsylvania