Change image in div onclick

I’m trying to figure out how to change the content in a div i’ve dynamically creating. This works fine if i’m trying to add text to the div, but adding an image doesn’t seem to work. There seems to be a syntax problem but i’m not sure what it is. Any ideas? Thanks in advance.

This is the code -

mydiv.setAttribute(‘onClick’,‘this.innerHTML = \’<img src=\‘image1.png\’>\‘’);

mydiv.setAttribute(‘onClick’,‘this.innerHTML = \’<img src=\‘image1.png\’>\‘’);

Thats some f*cked up code.

try a fuction…


<script>
function divPic() {
 document.getElementById('div1').innerHTML = "<img src='image1.jpg'>";
}
</script>

<div id="div1">
Click the link below to show a picture in this div.
</div>

<a href="#" onClick="divPic()">Show Picture in Div</a>

The problem is that the div is dynamically created so I need to use self to select it.