Chapter 37. HTML Directive Objects


  • Accessing non-displayed element objects

  • Linking operating-system specific stylesheet definitions

  • HTML, head, link, title, meta, base, and script elements

Thanks to the modern browser's desire to expose all HTML elements to the document object model, we can now access a variety of objects that represent many HTML elements that are normally invisible to the human viewer of a page. These elements are called directive elements because they predominantly contain instructions for the browser—instructions that direct the browser to locate associated content on the page, link in external specifications, treat content as executable script statements, and more.

As you browse through the objects of this chapter, you may wonder why they have so many properties that normally indicate that the elements occupy space on the rendered page. After all, how can a meta element have dimension or position on the page when it has no renderable content? The reason is that modern browsers internally employ some form of object-oriented behavior that lets all HTML elements—rendered or not—inherit the same set of properties, methods, and event handlers that any generic element has (see Chapter 15). The logical flaw is that unrendered elements can have properties and methods that don't genuinely apply to them. In such cases, their property values may be zero, an empty string, or an empty array. Yet the properties and methods exist in the objects just the same. Therefore, ...

Get JavaScript® Bible, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.