How to detect strictly adjacent siblings
问题 Consider the following HTML where IDs #p1 , #p2 and #p3 are siblings (see fiddle): <div id="container"> <span id="p1">Paragraph 1</span> <span id="p2">Paragraph 2</span> This is just loose text. <p id="p3">Paragraph 3</p> </div> These are my definitions of strict and loose siblings: I consider ID #p1 and #p2 strict siblings (because there is no text which is not encapsulated in any kind of html element between them. And ID #p2 and #p3 to be loose siblings. Given any element with a next