Thursday, April 21, 2011

Add and Remove DOM Elements..

Snippets for adding DOM elements dynamically to the defined DOM element.
Here, "mydiv2" is added dynamically as "mydiv"1's child.

    //Dynamically generate Div
    var newdiv = document.createElement('div');
    var divIdName ='mydiv2';
    newdiv.setAttribute('id',divIdName); = "565px"; = "480px"; = "0px"; = "0px"; = "absolute"; = "1px solid #000";

A good example by Dustin Diaz to remove DOM elements Dynamically.

removeElement JavaScript Function

function removeElement(divNum) {

  var d = document.getElementById('myDiv');

  var olddiv = document.getElementById(divNum);




Post a Comment


© 2011 GIS and Remote Sensing Tools, Tips and more .. ToS | Privacy Policy | Sitemap

About Me