[jQuery] Re: element creation using wrap behaves oddly

2008-09-26 Thread ricardobeat
Hmmm... Actually, after some tests I found my idea of this to be false. You can indeed attach event handlers before an element is inserted into the DOM. Sorry :D But I don't know what's weirder: this construct for wrapping/attaching a handler at the same time or that the wrap() function prevents

[jQuery] Re: element creation using wrap behaves oddly

2008-09-25 Thread darren
yea! weird huh? yes the workarounds do work (and there's even a few more that i can think of) but i was simply scratching my head when i came up against the problem. ill see if i can make sense of the source, and perhaps submit a ticket so that someone with a better understanding can give it a l

[jQuery] Re: element creation using wrap behaves oddly

2008-09-25 Thread darren
i don't see how creating the element, assigning the handler, and replacing or appending something works... yet, creating the element, assigning the handler, and wrapping it doesn't. can you help me understand what the difference is? On Sep 25, 5:39 pm, ricardobeat <[EMAIL PROTECTED]> wrote: >

[jQuery] Re: element creation using wrap behaves oddly

2008-09-25 Thread ricardobeat
It doesn't work for you because my code is not missing a ), actually I made a mistake on rewriting it. I'm assigning the click handler to the 'b' element which was wrapped, it's not inside the wrap function. It should read: $('b').wrap('').click(function(){ alert("foo"); }); The second snipp

[jQuery] Re: element creation using wrap behaves oddly

2008-09-25 Thread darren
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($('').click(function(){ alert("foo"); })); your element creation: $('') is equivalent to the shorthand i used: $("") in either case, the click handler doe

[jQuery] Re: element creation using wrap behaves oddly

2008-09-24 Thread ricardobeat
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($('').click(function(){ alert("foo"); }); Or if you want the click event assigned to and not $('b').wrap($('').parent().click(function(){ alert("foo"); }); - ricard