Archive for October, 2010

Add and Remove element

October 28, 2010 1 comment

We can add any element through javascript. It is so simple and easy.  Use below script to add and remove a div element.

<title>Add Element</title>
<script language=”javascript”>
this.num = 1;
function addElement(){
$top = document.getElementById(‘top’);
newId = document.createElement(‘div’);
id = ‘my’+this.num;
newId.setAttribute(‘id’, id );
newId.innerHTML = “<a href=’javascript:void(0); ‘ onclick=’removedThis( “+id +”)’ >Added Element”+id+”</a>”;
function removedThis( id ){
var d = document.getElementById(‘top’);
<input type=”button” name=”button” value=”Add Element” onclick=”addElement()” />
<div id=”top” ></div>

%d bloggers like this: