Blegger
Blegger

Reputation: 4292

Select the children of a sibling with a single expression in jQuery

Is it possible to select the children of a sibling of the current context in jQuery using a single expression similar to this?

$('~ div > span', this)

Unfortunately this does not work for me so I don't believe jQuery supports this type of chaining in an expression. I was however able to get the following methods to work:

$('> span', $('~ div', this))


$(this).siblings('div').children('span')

I am looking for a way to get the children of a sibling using the following API call, or for an explanation on why it is not possible:

jQuery( expression, context )

Upvotes: 4

Views: 7715

Answers (3)

Dave Gillem
Dave Gillem

Reputation: 516

I know this is a bit old but figured I'd answer in case anyone else is trying to do this. find() is the best way to do this

$(this).siblings('div').find('span');

Hope that helps

Upvotes: 6

Steve Paulo
Steve Paulo

Reputation: 18144

you could try $(this + "+div>span");

Upvotes: 1

Spencer Ruport
Spencer Ruport

Reputation: 35107

Try using $(this).next('div').children('span')

http://docs.jquery.com/Traversing/next

Upvotes: 0

Related Questions