First the use of “\n” which I expect to cause a line break. Example:
var name = "Peter"; var nextName = "John"; document.writeln("Hello, " + name + "\n"); document.writeln("Hello again, " + nextName + "!");
Hello, Peter Hello again, John!
and not the line break I anticipated.
Second: Use of firstChild:
Note: I entered a HTML description showing a body tag, with an h1 tag and element below at first.
(Unfortunately “What’s happening?” showed up when I entered the actual HTML, and replaced it, so I am now editing my message and removed the actual HTML code. I presume this HTML code triggered the “What’s happening?”)
var bodyElement = document.body;
var childElement = bodyElement.children; alert(childElement.tagName);
The result shows as ‘H1’ as expected.
If I replace the .children by .firstChild:
var childElement = bodyElement.firstChild;
The result shows as ‘undefined’
Where did I go wrong?
I have Windows 8.1 and tested it on Chrome and Explorer.
Thanks so much!