Is there a sexier way to write this jQuery selector?

I want to highlight all child elements of an element bodybefore an element with id foo(which is a child body). Since this does not look like a selector :before()or :after(), it works for me like this:

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

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

+3
source share
1 answer

This is not that shreds. Infact, using your "*" example in the selector, is WAY slower than the calling functions.

So, I would suggest using one function in the original selector:

$('body').children().first().nextUntil('#foo').andSelf() 

, DOM.

+4

Source: https://habr.com/ru/post/1740359/


All Articles