sorry for the double post, not sure how that happened.

ricardo, your code is missing a closing ) at the end. it should be...
$('b').wrap($('<a href="#"></a>').click(function(){
    alert("foo");
}));

your element creation: $('<a href="#"></a>')
is equivalent to the shorthand i used: $("<a href='#'/>")

in either case, the click handler does not get assigned for me, so i
am not sure how it works for you?






On Sep 24, 1:30 pm, ricardobeat <[EMAIL PROTECTED]> wrote:
> 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