jQuery doesn't select or operate on text nodes. Here's a plugin I wrote that will capture the text node and wrap it:
/*! * jQuery wrapNextTextNode Plugin v1.0 * http://outwestmedia.com/ */ $.fn.wrapNextTextNode = function(wrap) { return this.each(function() { var ns = this.nextSibling; while ( ns ) { if ( ns.nodeType == 3 ) { var node = $(wrap)[0]; ns.parentNode.insertBefore(node , ns); node.appendChild( ns ); break; } ns = ns.nextSibling; } }); }; You'd use it like this: $('#1').wrapNextTextNode('<div id="3"></div>'); Cheers, - Jonathan On Mon, Apr 6, 2009 at 9:56 PM, FameR <dj.fa...@gmail.com> wrote: > > Is there way to create element that consists html between two another > elements? > > for exmple: > from this > <div> > Some st > <div id="1">ra</div> > nge foobarded > <div id="2"><div> > text goes here > </div> > > to: > > <div> > Some st > <div id="1">ra</div> > <div id="3">nge foobarded</div> > <div id="2"><div> > text goes here > </div> > > or: > > <div> > Some st > <div id="3">ra > nge foobarded > <div> > text goes here > </div> > >