Sam Sam - 4 years ago 110
jQuery Question

Target elements that come after a specific element with CSS/JS

Using Javascript/jQuery or a CSS selector, how would I target elements that come after a specific element? To be clear, I don't mean directly after (adjacent to), I mean any and all matching elements that exist further down the page.

Imagine a group of


<p id="special">Ipsum</p>

Now I want to target all of the
s that come after
... so the ones with content "Dolor", "Sit", and "Amet". I want there to be some selector available like:

$('p#special::allAfter p').each(...

How would I do this?

Answer Source

nextAll() is a jQuery function that you are looking for.

See this documentation:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download