Do a loop like this (this example adds alternating colors to the
groups of paragraphs):

$('h5').each(function(i){
    var colors = ['green', 'red', 'blue'];
    n = $(this), ps = [];
    while( (n = n.next()).length && !n.is('h5') )
       ps.push( n[0] );

   $(ps).css('color', colors[i%3]);
});

Or use this (by John Resig, I think I've posted this a dozen times
already..):

jQuery.fn.nextUntil = function(expr) {
   var match = [];
   this.each(function(){
       for( var i = this.nextSibling; i; i = i.nextSibling ) {
           if ( i.nodeType != 1 ) continue;
           if ( jQuery.filter( expr, [i] ).length ) break;
           match.push( i );
       }
   });
   return this.pushStack( match, arguments );
};

$('h5').each(function(){
     $(this).nextUntil('h5').bleh();
});

On May 27, 2:32 pm, Andy <[email protected]> wrote:
> Thanks for the suggestion!
>
> That sort of works, but it's also getting the <p> tags AFTER the next
> H5, and I don't want it to.
>
> On May 27, 1:24 pm, "Mauricio \(Maujor\) Samy Silva"
>
> <[email protected]> wrote:
> > Try:
> > $('h5').nextAll('p');
>
> > Maurício
> >   -----Mensagem Original-----
> >   De: Andy
> >   Para: jQuery (English)
> >   Enviada em: quarta-feira, 27 de maio de 2009 14:11
> >   Assunto: [jQuery] selecting next()'s until I reach a tag
>
> >   Is there a way for me to add the next several blocks until I get to a
> >   specific tag?

Reply via email to