Click to See Complete Forum and Search --> : Image/Div Event Problems


Stevil
02-03-2004, 10:14 PM
Hey all,

I'm currently working on a script which creates images using the createelement function, I've got this working BUT I'm trying to capture events (mainly on click) on these images which I seem to be having troubles with :(

the code is:

bDivs[bDivCount]=document.createElement("a");
bDivImgs[bDivCount]=document.createElement("img");
bDivs[bDivCount].appendChild(bDivImgs[bDivCount]);
bDivs[bDivCount].style.position="absolute";

I've tried:

bDivs[bDivCount].onmousedown="alert('now');";
bDivs[bDivCount].onClick ="alert('now');";

These didn't work so I even tried using href on the images:
bDivs[bDivCount].href="javascript:selBuilding("+bCount+");";

(I've tried ALL these with both the bDivImgs an bDivs, won't bother posting the same code twice.)

Using a href link seems to work ok in I.E v6 but not in I.E v5.0, any advice anyone may have for me would be greatly appareicated.

Stevil

fredmv
02-03-2004, 10:45 PM
One (or both) of these should work correctly:bDivs[bDivCount].setAttribute('onclick', 'alert("foo");');bDivs[bDivCount].onclick = function() { alert('foo'); }