I only did some basic testing, but this will do it:
jQuery.fn.wrapInner = function(html){
return this.each(function(){
var wrap = $(html), lowest = wrap[0].firstChild;
while ( lowest.firstChild )
lowest = lowest.firstChild;
while ( this.firstChild )
lowest.appendChild( this.firstChild );
wrap.appendTo( this );
});
};
--John
On 2/19/07, Oliver Boermans <[EMAIL PROTECTED]> wrote:
> Tidy! Thanks John.
> While that is suits my particular purpose nicely, I'm curious, how
> would you to change it to insert the to-be-wrapped content into the
> _deepest_ point in the supplied HTML snippet.
> Like regular wrap. eg:
>
> Usage:
> $('p').wrapInner('<strong><a href="/"></a></strong>');
>
> To make this:
> <p>Hello world!</p>
>
> Into:
> <p><strong><a href="/">Hello world!</a></strong></p>
>
> Cheers
> Ollie
>
> On 20/02/07, John Resig <[EMAIL PROTECTED]> wrote:
> > 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 );
> > });
> > };
> >
> > > 2007/2/19, Oliver Boermans <[EMAIL PROTECTED]>:
> > > > $.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();
> > > > });
> > > > };
> > > > Perhaps someone knows how make this work without the additional
> > > > argument?
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/