When I have elements surrounded by a P tag, or SPAN tag, why does jQuery fail to find next(), even though the element does indeed have a direct sibling?
<p>
<img src="" width="40" height="40"
onmouseover="alert('next() is ' + $(this).next().length)" />
<-- mouseover me
<div></div>
</p>
If I change the P tag to a SPAN tag, same problem occurs. If I remove the P tag or change it to almost any other tag, it works fine.
JSFiddle: http://jsfiddle.net/YHTGT/
divis not a valid node within apnode, so the parser is probably eliding it entirely. If it had content, I’d expect it to be moved in the DOM tree to after thepnode, making it not a sibling of theimg.Changing the
divto aspanworks because thespanis allowed there.