...

View Full Version : onclick for appended image not working



transmoderata
06-21-2012, 04:27 AM
page: www.therabbitshome.com (http://www.therabbitshome.com)

Click "BROWSE GALLERIES", then "(2010-2011) GALLERY 1". Now click the first thumbnail picture to the left. An alert box should come up, but it doesn't.


var gOutOf=document.createElement('img');


gOutOf.onclick="clickGOutOf()";


function clickGOutOf() {
alert("clicked");
}

Help pls?

xelawho
06-21-2012, 04:45 AM
either


gOutOf.onclick=clickGOutOf;
or

gOutOf.onclick=function(){clickGOutOf()};

transmoderata
06-21-2012, 04:46 AM
o

thx.

transmoderata
06-21-2012, 05:03 AM
And if I may say so, it makes no sense to me why the format would be different in the markup and in JS. But that's javascript I guess...nonsensical.

xelawho
06-21-2012, 02:11 PM
the simple answer would be that html is html and javascript is javascript.

the slightly longer answer would be that in html, an inline event handler like onclick accepts javascript between the quotes. But wrapping something in quotes in javascript converts it into a string, meaning that the function will never execute.

that's my take on it, anyway - makes sense if you think about it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum