As Toby said you are trying to add a variable/element (newP) which
does not exist in the last line. try this:
document.getElementsByTagName('body')[0].appendChild
(document.createElement("p").appendChild(document.createTextNode
("helloWorld")));-shavinder On Oct 23, 8:21 pm, jk <[email protected]> wrote: > Is it alright to ask general questions about javascript here? > I'm trying to understand the mental model(s) of the dom. > I'm experimenting with adding and removing elements from the page. > I got this to work: > > ` function addParagraph() { > ` var newP = document.createElement("p"); > ` var newT = document.createTextNode("hello, world!"); > ` newP.appendChild(newT); > ` document.getElementsByTagName('body')[0].appendChild(newP); > ` } > > my question is, if the above works, why doesn't this? > (replaced variable `newP`): > > ` function addParagraph() { > ` var newT = document.createTextNode("hello, world!"); > ` document.createElement("p").appendChild(newT); > ` document.getElementsByTagName('body')[0].appendChild(newP); > ` } > > What's at work here? does the variable capture something being passed > from the method? > why can't I use appendChild and createElement within the same > statement? I guess I thought that variables were mostly a shortcut, so > it seemed to me you COULD write the above example in one line, without > variables. (note: I can subsitute the var `newT` in the sample above > with no issues.) > > admittedly, my knowledge of javascript is slim, but I find it hard to > learn it without also understanding its application to the dom. the > tutorials at w3schools.com are so dated. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

