On Sep 23, 11:00 pm, "Brandon Aaron" <[EMAIL PROTECTED]> wrote:
> You could reverse the logic and use the prependTo method instead of prepend.
>
> $('.container').each( function() {
> $('<a class="dosomething" href="...'">Do something</
> a>')
> .prependTo(this)
> .click(doSomething);
Smarter indeed. Thx.
> You could also use the Live Query plugin to create a set of behaviors
> associated with selectors that will bind those behaviors to all newly
> matched elements.http://jquery.com/plugins/project/livequery
I wasn't aware of this plugin. sounds like a really smart addition to
jquery ! Thanks for the info
X+
> --
> Brandon Aaron
>
> On 9/23/07, xavier <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hello,
>
> > I found myself adding elements to a page, and then adding behaviour to
> > these elements.
>
> > What I did was :
>
> > $('.container').each(function(){
> > $(this).prepend('<a class="dosomething" href="...'">Do something</
> > a>')
> > .find(".dosomething").click(function(){return
> > doSomething(this);});
> > ...
>
> > It works, but I don't find very elegant this add, search the element I
> > just added and bind the event way.
>
> > Is there a way to combine properly the prepend and the bind an event
> > steps ?
>
> > Thanks in advance,
>
> > X+