On Dec 18, 3:47 am, gorfbox <[email protected]> wrote:
> I'm having a dickens of a time with something that should be easy.
> When using $("body").append to place an anchor containing an "onClick"
> statement in the html body, the code is executed and the anchor is
> shown, but the onclick doesn't work. Strangely enough, if an anchor
> with an onClick is statically placed in the html code it works fine.
>
> This only happens when using the browser shown in Outlook; Chrome and
> IE8 have no problems. Here's the code I'm using...
>
> http://pastie.org/748407
There's a long thread on the dev group [1] about the use of .attr().
I would suggest that you simply not try to use it to set event
listeners. Instead, use .bind('click', fn) or the shortcut .click
(fn).
So instead of this:
$("body").append($('<a>').attr({onClick:"alert('dynamic
test');return false"}).text("Dynamic")) ;
try something like this:
$("body").append($('<a>').click(function(){alert('dynamic
test');return false;}).text("Dynamic"));
See this for an example:
http://jsbin.com/eqiva (code http://jsbin.com/eqiva/edit)
I don't know if this will fix your Outlook issue, but I think it sets
you off in a better direction.
Good luck,
-- Scott
[1] http://tinyurl.com/ydu7hsz