It seems like this would be a better solution:

jQuery.fn.wrapInner = function(html){
  return this.each(function(){
     var wrap = $(html);
     while ( this.firstChild )
       wrap.append( this.firstChild );
     wrap.appendTo( this );
  });
};

no need for a filter, and you don't lose your events. You can use it like this:

$("p").wrapInner("<a href=''></a>");

--John

On 2/19/07, Christian Bach <[EMAIL PROTECTED]> wrote:
> Hi!
>
> Here is the new version.
>
> jQuery.fn.wrapInner = function(o) {
>     return this.each(function(){
>                  var jQ = jQuery(this);
>                  var c = jQ.html();
>                  jQ.empty().append(o.el).filter(o.id).html(c);
>     });
> }
>
> $("p").wrapInner({el: '<a href="http://jquery.com";>', id: 'a'});
>
> Before:
> <p>I will become a link to jQuery.com</p>
>
> After:
> <p><a href="http://jquery.com";>I will become a link to jQuery.com</a></p>
>
>
> /christian
>
>
>
>
> 2007/2/19, Oliver Boermans <[EMAIL PROTECTED]>:
> > Hey all,
> >
> > I had some trouble today attempting to use the simple wrapinner plugin
> > with jquery 1.1.1.
> > http://motherrussia.polyester.se/jquery/wrapInner/
> >
> > Some modification to the plugin code was required to make it do what I
> > was looking for.
> >
> > // The additional argument is 's' (for selector)
> >
> > $.fn.wrapInner = function(e,s) {
> > return this.each(function(){
> > var o = $(this);
> > var c = o.html();
> > o.empty().append(e).find(s).append(c).end();
> > });
> > };
> >
> > The modified example usage:
> > $('p').wrapInner('<a href="/"><\/a>','a');
> >
> > To make this:
> > <p>Hello world!</p>
> >
> > Into:
> > <p><a href="/">Hello world!</a></p>
> >
> > Perhaps someone knows how make this work without the additional argument?
> >
> > Cheers
> > Ollie
> >
> > _______________________________________________
> > jQuery mailing list
> > [email protected]
> > http://jquery.com/discuss/
> >
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to