Hixie's Natural Log

2006-10-17 21:43 UTC The DOM0 Legacy: document.title

I'm trying to specify document.title. Here's a list of quirks and outright bugs that I have found so far:

title elements created by the parser don't have child nodes, but you can see their value in the innerHTML serialisation. (DOM-created title elements do have child nodes, however.)
Adding a title element via the DOM has no effect on document.title.
The first title element that is parsed by the parser is associated with document.title. If there is already such a node, then the new one is ignored by the parser.
Changing document.title changes the innerHTML of the associated title element, potentially creating one at the start of the head element if required.
Trying to append a child text node to the magic title element results in an exception being raised: "Unexpected call to method or property access".
Trying to change the magic title element's innerHTML gives an "Unknown runtime error".
Firefox trunk
Setting document.title doesn't affect the DOM, and is sticky; further changes to the DOM no longer affect document.title.
The first title element that the parser sees sets the document.title value to the element's textContent.
Safari trunk
If a title element is inserted into the DOM, it is associated with document.title, unless another node is already associated with it.
If the associated title element is removed from the document, it loses its association.
Setting document.title directly doesn't affect the DOM but sets an override that causes further accesses of that attribute to return the set value, until the set value is forgotten.
Appending things to the associated title element works per the DOM, and causes any override setting of the document.title to be forgotten.
Setting a title element's innerHTML attribute rasises a NO_MODIFICATION_ALLOWED_ERR exception.
Getting document.title returns the concatenation of all the text node children of the associated title element, unless an override is in effect, in which case that is returned instead.
In the parser, a title start tag doesn't imply a head start tag, nor do title tags in the body end up as elements in the head.
Parsed title elements always have a text node child, even when that node is empty.
Setting document.title when there's no title element in the DOM does nothing, otherwise it deletes all the child nodes of the first title element in the DOM and then (if it wasn't set to the empty string) appends a single text node containing the new value.
Getting document.title returns the text of the first node (if it's a text node) of the first title element in the document (if there is one).
You can append a title element (or indeed any element) to the Document node, such that the document has more than one root node.