0

I want to add image in check box in HTML so that when i click on check box it should be replaced by an image.What is the way to do it?

Eshika
  • 321
  • 1
  • 8
  • 20
  • 2
    possible duplicate of [add an image to a html type input check box or radio](http://stackoverflow.com/questions/5117116/add-an-image-to-a-html-type-input-check-box-or-radio) – Pekka May 10 '11 at 12:06

1 Answers1

0

Let cb be a checkbox, and src the source of the image you want to be displayed.

cb.onclick = function(){
    if(!this.img){
        var img = this.img = document.createElement("image");
        img.src=src;
        img.cb = this;
        img.onclick = function(){
            this.parentNode.replaceChild(this.cb,this);
            }
        }
    this.parentNode.replaceChild(this.img,this);
    }
Luc125
  • 5,752
  • 34
  • 35