I believe you can't assing an event handler to an element before it is
added to the DOM. This works for me:

$('b').wrap($('<a href="#"></a>').click(function(){
    alert("foo");
});

Or if you want the click event assigned to <a> and not <b>

$('b').wrap($('<a href="#"></a>').parent().click(function(){
    alert("foo");
});

- ricardo

On Sep 24, 3:08 pm, darren <[EMAIL PROTECTED]> wrote:
> i just want to bring this up for discussion to see what people have to
> say about it and to further my understanding of how jquery works and
> why it works that way. maybe its a bug?
>
> imagine the base code <b>Hello World!</b>
>
> // fails to assign click handler:
>$("<a href='#'/>").click(function(){
    alert("foo");
})
>
> // also fails... wrapAll, wrapInner etc
>
> // works as expected:
> $("b").replaceWith($("<a href='#'>Hello World</a>").click(function(){
>     alert("foo");}));
>
> // also works as expected: html, prepend, append, after, before,
> etc...
>
> i found this odd. thoughts?

Reply via email to