How can I add a class to the p tag if the next tags that follows is an unordered list?
Sample mark-up:
<p>paragraph</p>
<p>paragraph 2</p>
<ul>
<li>line 1</li>
</ul>
So the first p tag has no class, and the second p tag would have class ‘foo’ since the next element after it is an unordered list.
Think about it the other way round; target the
ul, and select the previous elements of the containedul‘s if they arep‘s, and add a class to them.See the
prev()method for more info.