First, id's that are only (or begin with) numbers are invalid. You can work with text nodes in a limited way in jQuery using the contents() method. You could use contents() with filter() to achieve what you're after.
//this will wrap any text between two divs (assumes your containing div has id #container) var test = $('#container').contents(); test.filter(function(n){ if( this.nodeType == 3 && $(test[n-1]).is('div') && $(test[n+1]).is ('div') ){ return this; } }).wrap('<div id="d3"></div>'); or if you just want to wrap the text node following div#1 you could do: var test = $('#container').contents(); test.filter(function(n){ if( this.nodeType == 3 && $(test[n-1]).is('div#d1') ){ return this; } }).wrap('<div id="d3"></div>'); Something you might want to consider, especially for special cases where you'll only be doing it once. On Apr 7, 3:59 pm, FameR <dj.fa...@gmail.com> wrote: > Thanx a lot! > > On 7 апр, 06:34, "Jonathan Sharp, Out West Media" <jquery- > > li...@outwestmedia.com> wrote: > > 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>