![]() ![]() Union types are an advanced topic that we’ll cover in a later chapter.Īs a note: we encourage the use of strictNullChecks when possible, but for the purposes of this handbook, we will assume it is turned off. In cases where you want to pass in either a string or null or undefined, you can use the union type string | null | undefined. However, when using the strictNullChecks flag, null and undefined are only assignable to unknown, any and their respective types (the one exception being that undefined is also assignable to void). That means you can assign null and undefined to something like number. ![]() You'll find these terms and others to be introduced and used throughout the documentation.By default null and undefined are subtypes of all other types. It's common to refer to any Attr node as an attribute, for example, and to refer to an array of DOM nodes as a nodeList. There are also some common terminology considerations to keep in mind. Item() method for this purpose, and you can also add and remove items from a namedNodeMap. Attributes are nodes in the DOM just like elements are, though you may rarely use them as such.Ī namedNodeMap is like an array, but the items are accessed by name or index, though this latter case is merely a convenience for enumeration, as they are in no particular order in the list. When an attribute is returned by a member (e.g., by the createAttribute() method), it is an object reference that exposes a special (albeit small) interfaceįor attributes. The latter uses the typical array syntax to fetch the second In the first, item() is the single method on the nodeList object. In an HTML document, elements are further enhanced by the HTML DOM API's HTMLElement interfaceĪs well as other interfaces describing capabilities of specific kinds of elements (for instance, HTMLTableElement for elements).Ī nodeList is an array of elements, like the kind that is returned by the method document.querySelectorAll(). More basic Node interface, both of which are included together in this reference. element objects implement the DOM Element interface and also the Rather than saying, for example, that the document.createElement() method returns an object reference to a node, we just say that this method returnsĮlement that has just been created in the DOM. It refers to an element or a node of type element returned by a member of the DOMĪPI. In an HTML document, an object can be an element node but also a text node or attribute node. The DOM document Reference chapter describes the document object.Įvery object located within a document is a node of some kind. Which it belongs), this object is the root document object itself. When a member returns an object of type document (e.g., the ownerDocument property of an element returns the document to The following table briefly describes these data types. Note: Because the vast majority of code that uses the DOM revolves around manipulating HTML documents, it's common to refer to the nodes in the DOM as elements, although strictly speaking not every node is an element. But there are a number of different data types being passed around the API that you should be aware of. This page tries to describe the various objects and types in simple terms.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |