$("div :last-child");  finds all of the last-child elements, including
descendant elements (e.g.  if there were an <a> inside the span in
your example it would be returned too). You can also not worry about
the parent at all and just use the sibling selector:

 //or you could use :last-child

As Ricardo suggested, you can use 'this' :

$(this).nextAll(':last');

On Feb 11, 10:05 pm, Ricardo Tomasi <ricardob...@gmail.com> wrote:
> $(this).parent().children(':last') //or :last-child - assuming 'this'
> is the input element
>
> On Feb 12, 3:09 am, Risingfish <risingf...@gmail.com> wrote:
>
> > Thanks Nic,
>
> > How about if I'm using the input tag as the base? Can I do something
> > like $("self:parent:last-child") ?
>
> > On Feb 11, 8:13 pm, Nic Luciano <adaptive...@gmail.com> wrote:
>
> > > $("div :last-child");
>
> > > (or this wacky way I tried before I learned CSS selectors....
> > > $("div").children()[$("div").children().size() - 1])...)
>
> > > Nic 
> > > Lucianohttp://www.twitter.com/niclucianohttp://www.linkedin.com/in/nicluciano
>
> > > On Wed, Feb 11, 2009 at 9:49 PM, Risingfish <risingf...@gmail.com> wrote:
>
> > > > Hi James, apologize for not being more precise. I'm using the input
> > > > element as my base reference. So using that input element, I want to
> > > > get the last sibling under the div. You are correct that if the span
> > > > is not then the input is what I want. I may need to add more tags
> > > > later (I'm sure you know hoe the development process goes when
> > > > customers are involved. :) ), so a reliable way to get the last tag
> > > > would be nice. Thanks!
>
> > > > On Feb 11, 7:21 pm, James <james.gp....@gmail.com> wrote:
> > > > > When you say "last sibling in a parent", what does that mean? Which
> > > > > element is your base reference?
>
> > > > > In your example:
> > > > > <div>
> > > > >   <input ...... />
> > > > >   <span>...</span>
> > > > > </div>
>
> > > > > Do you mean your <div> is the base reference, and you want to find the
> > > > > last child (thus, <span>) relative to that?
> > > > > And if <span> is not there, you want <input>?
>
> > > > > On Feb 11, 4:12 pm, Risingfish <risingf...@gmail.com> wrote:
>
> > > > > > Before I accidentally hit enter, this is what I was trying to type: 
> > > > > > :)
>
> > > > > > <div>
> > > > > >   <input ...... />
> > > > > >   <span>...</span>
> > > > > > </div>
>
> > > > > > The span might or might not be there, so I would like to just get 
> > > > > > the
> > > > > > last sibling in a parent.
>
> > > > > > Thanks!

Reply via email to