views:

45

answers:

1

Hi,

This does not seem to be in the docs of jQuery API, so it probably does not exist, but just wanted to get confirmation from fellow experts.

Is there an equivalent to $('prev ~ next') but for previous siblings? (No methods, just selectors)

+2  A: 

How about negating the selector?

$('parent > *:not(prev ~ next)')

Working example on JSBin

casablanca
thanks casablanca, that is I think the best way to do it without getting very messy in the selector!
fabjoa
I have to say, I think it ridiculous to use a selector like this instead of the `prev` function. Seriously, what are you gaining? If you knew how jQuery handles this selector beneath the surface you would not use it.
Josh Stodola
@Josh: Totally agree with you. It's going to be terribly inefficient, but I don't know why the OP wants it this way.
casablanca
just out of curiosity actually. wondering why there was a selector for next and not one for prev. playing around with a language is also a good way to learn about it ;)
fabjoa
@casablanca I am half-tempted to run benchmarks on your JSBin example vs. `$("#parent > #a4").prevAll("div").css('color', 'red');​​​​​​​​​​​​​​`
Josh Stodola