Wow FND! I could have never guessed. Thanks!

Its here too at https://developer.mozilla.org/En/DOM/Node.appendChild:


var appendedElement = element.appendChild(child);

The returned element is the child which is *appended*. So this line
does NOT return element "p", it returns the helloworld textnode.

document.createElement("p").appendChild(document.createTextNode
("helloWorld"))

Is the element "p" being created? I would hazard a guess that it *is*
being created. But in the following line the element p is not appended
to the body but is left orphan, and the returned appended child text
node goes on further to be appended to the body element in this line:

document.getElementsByTagName('body')[0].appendChild
(document.createElement("p").appendChild(document.createTextNode
("helloWorld")));

The next logical question is what does the above line return? The
helloworld Textnode still!

Thanks to FND for this again.

-shavinder


On Oct 30, 8:02 pm, FND <[email protected]> wrote:
> > May I suggest you moved on and consider [using jQuery]
>
> 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
>
> >http://jksjs.s3.amazonaws.com/ce1.htmland
> >http://jksjs.s3.amazonaws.com/ce2.html
>
> I assume you're aware that these are not valid HTML4 documents?
> (It looks a little like HTML5, but that might be coincidental?)
>
> -- F.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to