Wednesday, 23 November 2011

Adding HTML Tags Dynamically and Styling them with help of JavaScript

<html>
<head>
<script type="text/javascript">

function loadDoc()
{
var newelement=document.createElement("P");
document.body.appendChild(newelement);
newelement.appendChild(document.createTextNode("HellowWorld"));

var divElement=document.createElement("DIV");
divElement.style.width="100px";
divElement.style.height="100px";
divElement.style.backgroundColor="RED";
//divElement.style.styleFloat="left";   //for I.e property is styleFloat
divElement.style.cssFloat="left";       // for other browsers  property is cssFloat 
document.body.appendChild(divElement);  
                                           

}
</script>
</head>
<body>

<div id="myDiv" style=" width:100px; height:100px;">I am in HTML File  </div>
<p>This Script is written by Tahir Khalid ALL Right Reversed</p>
<input  type="button" onClick="loadDoc()" />

</body>
</html>

No comments:

Post a Comment