Why does HTML construction throw away some text objects and keep others?

Why does HTML construction throw away some text objects and keep others?


Hi All,
My name is Ingy döt Net. I'm working a Perl/CPAN module port of
jQuery, called pQuery.pm. Since I'm going over the jQuery code in
detail I'll likely have a few questions. I've been using jQuery for
about 4 months for work (Socialtext) and play, and love it.
Here's something I just found...
I noticed some time ago that jQuery functions seem to only select DOM
node elements and eschew DOM text elements. This makes sense to me.
However I noticed that this constructor:
foo = jQuery('

aaa

bbb

ccc

')
produces:
[p, "bbb", p]
I also noticed that:
foo.html("xxx")
sets both p nodes innerHTML in 1.2.2, which was fixed from 1.2.1. Good
job.
But then I noticed that:
foo = jQuery('aaa

bbb

ccc

ddd

eee')
produces:
[p, "ccc", p]
What gives? If you are going to allow constructors to put text nodes
in the jQuery object, and make methods expect/ignore text nodes
appropriately, why not allow text nodes at the beginning and end?
This could easily lead to unexpected missing data with constructors
like this:
jQuery(bar.innerHTML)
Looking forward to hacking with you guys, Ingy