
Signature
John H Clark
www.weownit.coop
John H Clark wrote ::
> During the initialization of a page I use the following script to create an
> image then append the image to an existing div element.
[quoted text clipped - 3 lines]
> theImage.src = "gallery/image.jpg";
> var mouseAttribute = document.createAttribute("onclick");
use attachEvent (for IE) and addEventListener (for other browsers) to add
the event.
> mouseAttribute.value = "javascript:displayImage(this.id)";
dont use javascript protocol here. it will not work. use :
displayImage(this.id)
> theImage.setAttributeNode(mouseAttribute);
> var existingDiv = document.getElementById("existingDiv");
> existingDiv.appendChild(theImage);
----
var theImage = new Image();
theImage.id = "anId";
theImage.src = "gallery/image.jpg";
theImage.onclick=function(){displayImage(this.id)} // this will work on
all browsers
var existingDiv = document.getElementById("existingDiv");
existingDiv.appendChild(theImage);
----
or
----
var theImage = new Image();
theImage.id = "anId";
theImage.src = "gallery/image.jpg";
if(thImage.attachEvent)
theImage.attachEvent("onclick",function(){displayImage(this.id)})
else if(theImage.addEvenetListener){
theImahe.addEventListener("click",function(){displayImage(this.id)},false)
var existingDiv = document.getElementById("existingDiv");
existingDiv.appendChild(theImage);
----
> However, in Firefox an event is fired and the response is as expected.
Really !!
Good Luck, Ayush.

Signature
Setup Outlook Express to read MS Newsgroups :
http://www.microsoft.com/windows/ie/support/newsgroups/howto.mspx