I believe one should have a firm grasp of JavaScript and the DOM before
using abstractions like jQuery. (Although that's not necessarily a
strictly linear progression; experimenting with jQuery can be
educational WRT the underlying technologies.)
> the one-liner version still does not work correctly
This is because your code returns the last element in the chain rather
than the original node:
document.createElement("p");
// returns p element
document.createElement("p").
appendChild(
document.createElement("em")
);
// returns em element
document.createElement("p").
appendChild(
document.createTextNode("helloWorld")
);
// returns text node
I assume you're aware that these are not valid HTML4 documents?
(It looks a little like HTML5, but that might be coincidental?)
-- F.
It is being created in-memory, but does not persist in the document.
Thus the object's memory will be deallocated (freed) when it goes out of
scope, i.e. the function ends - though that might depend on the
respective JavaScript engine's garbage collection. (I'm not an expert on
such low-level details.)
Note that jQuery's chaining can work a little different, depending on
which method is invoked.
-- F.
Both create a P element with a text node ("<p>hello, world!</p>").
However, that element is never appended to the document.
You might wanna read through some of the articles listed here:
http://dev.opera.com/articles/view/1-introduction-to-the-web-standards-cur/#toc
-- F.