Is there a sexier way to write this jQuery selector?

Posted by Bears will eat you on Stack Overflow See other posts from Stack Overflow or by Bears will eat you
Published on 2010-04-08T17:35:25Z Indexed on 2010/04/08 17:43 UTC
Read the original article Hit count: 258

Filed under:
|

I want to select all the children of the body element before element with id foo (which is a child of body). Since it doesn't look like there are :before() or :after() selectors, I've got it working like this:

$('body > :first').nextUntil('#foo').andSelf();

but it seems kludgy. Could this be done with fewer function calls, or more efficiently? Maybe something akin to $('body > *:before(#foo)') ?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery