How to remove images to the div tag

Posted by Nishithraj under JavaScript on 2/3/2010 | Views : 7389 | Status : [Member] | Replies : 3
In my program, I'm adding images to the div tag dynamically based on the user uploads the images using innerHtml property.

I need to remove this images also while clicking that images by the user. How can we do that?


I have done like following.

div.innerHtml= "<img scr=''location' id="img01' onclick="RemoveMe();">

Since it is dynamically created how can we remove these images?

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan



Responses

Posted by: Sagarp on: 2/3/2010 [Member] Bronze

Up
0
Down
Hi

ref this

http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 2/3/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
use

while(div.firstChild)

div.removeChild(div.firstChild);


Easiest way to remove all elements from a div.

www.abhisheksur.com

Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: RtpHarry on: 2/3/2010 [Member] [MVP] Bronze

Up
0
Down
Sagarps link to the Dustin Diaz tutorial is a better technique than the one you are using.

These days it makes sense to use jQuery or a similar library. This makes adding dom elements easy and cross browser friendly.

It also makes attaching click events to it easy and you can add a handler to delete itself easy.

Easy easy easy :)

Check out jQuery.com to get your feet wet.

Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response