Jump to content

Document


Drycodez

Recommended Posts

When opening a document as an HTML one, it implicitly adds required elements like <html> and <title>. You need to make sure that either you have a valid HTML document or you serve it as an XML document to prevent these additions.Also, whitespace is counted as a node, so even if the document was served as XML, "document.firstChild.firstChild" would match the first whitespace of the body element. Right now, it's probably matching the whitespace of the implicitly added HTML element, and inherently doesn't work because having something other than one head and one body is invalid.

Link to comment
Share on other sites

When opening a document as an HTML one, it implicitly adds required elements like <html> and <title>. You need to make sure that either you have a valid HTML document or you serve it as an XML document to prevent these additions.Also, whitespace is counted as a node, so even if the document was served as XML, "document.firstChild.firstChild" would match the first whitespace of the body element...
thanks!
Link to comment
Share on other sites

document.lastChild will not refer to the last element in the body, if that's what you're thinking. As with people, a child is an immediate descendant. The last child of document should be the <html> element. (I suppose it could be a text node, also.)

Link to comment
Share on other sites

document.lastChild will not refer to the last element in the body, if that's what you're thinking. As with people, a child is an immediate descendant. The last child of document should be the <html>...
hmmm, kinda confusing! i thought the last child of a document is the <body> tag! What do you mean? Plz make me understand!
Link to comment
Share on other sites

Assuming the document is well formed, the <body> element is the last element contained by the <html> element. The document itself contains (1) the <!DOCTYPE> element and (2) the <html> element.

Link to comment
Share on other sites

Why don't you figure out what elements you're trying to reference? Use Firebug and console.log to examine the elements you're working with and then you can figure out why it doesn't do what you expect. You can look at the entire DOM tree through Firebug.

Link to comment
Share on other sites

Why don't you figure out what elements you're trying to reference? Use Firebug and console.log to examine the elements you're working with and then you can figure out why it doesn't do what you expect. You can look at the entire DOM tree through Firebug.
ok, thanks!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...