aspx Tutorial

NET Articles,jQuery demo, with jQuery, online tutorial,Jquery, SilverLight, Javascript,,JSON, MVC,.NET Articles,demo, Web Services,
Advertise Here


Get our toolbar!


Posted by Aamir Hasan   on Monday, January 31, 2011 Total Views:  

In this example, you will see how to create DIV tag programmatically using JavaScript. JavaScript DOM features are Document object, createElement method, style object, ClassName property, margin property, innerHTML property, setAttribute method, id property,document.body, appendChild method.

Here’s an example

<html xmlns="">

<head runat="server">

    <title>Create Dynamic div using javascript</title>

    <style type="text/css">



            color: #999;

            padding: 10px;

            width: 250px;

            height: 150px;

            background-color: #fafafa;

            font-size: 12px;

            font-family: verdana;

            border: solid 1px #666;



    <script type="text/javascript" language="javascript">

        function CallDiv() {

            var divTag = document.createElement("div");

   = "divDyn";

            divTag.className = "classA";

            divTag.innerHTML = "Welcome to ";






    <form id="form1" runat="server">


           <input id="btClick" type="button" value="Click" onclick="CallDiv();" />

        <br />







Download (1.06 kb)

See live demo

Category: All | Javascript
Protected by Copyscape Online Plagiarism Tool

Add comment

  Country flag

  • Comment
  • Preview

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5