.after() only changes the stack if the first element in the set is disconnected. This is unfortunate, because
.end() cannot be used with the same result if
.after() is called on an ''empty'' set vs a ''non-empty'' set. You don't always know whether there are elements in the set, and more importantly, it should not matter.
The second div doesn't turn red because it doesn't have any children. The fiddle is contrived, of course, but in real cases you don't know whether there are any children - I'd expect both
.end() calls to select the div again.
I did note that the docs state that
.after() acts differently on a set of disconnected nodes. However, jQuery thinks an empty set is disconnected as well, causing this issue.