diff --git a/docs/ch13.md b/docs/ch13.md index 322a22d252201352e60a04e88547594b5ce45c8f..eb4f134f2fbcb6ef35c511dde9faaf7b6ccf6f7d 100644 --- a/docs/ch13.md +++ b/docs/ch13.md @@ -306,8 +306,8 @@ Let’s bring this back to our URL-fetching example. When c1 returns p4, p2 is r This can be one of the trickiest parts of JavaScript to understand, and you may need to read this section more than once. Figure 13-1 presents the process in visual form and may help clarify it for you. -js7e 1301 -Figure 13-1. Fetching a URL with Promises +Fetching a URL with Promises + ### 13.2.4 More on Promises and Errors Earlier in the chapter, we saw that you can pass a second callback function to the .then() method and that this second function will be invoked if the Promise is rejected. When that happens, the argument to this second callback function is a value—typically an Error object—that represents the reason for the rejection. We also learned that it is uncommon (and even unidiomatic) to pass two callbacks to a .then() method. Instead, Promise-related errors are typically handled by adding a .catch() method invocation to a Promise chain. Now that we have examined Promise chains, we can return to error handling and discuss it in more detail. To preface the discussion, I’d like to stress that careful error handling is really important when doing asynchronous programming. With synchronous code, if you leave out error-handling code, you’ll at least get an exception and a stack trace that you can use to figure out what is going wrong. With asynchronous code, unhandled exceptions will often go unreported, and errors can occur silently, making them much harder to debug. The good news is that the .catch() method makes it easy to handle errors when working with Promises. diff --git a/docs/ch15.md b/docs/ch15.md index 5616cdcbf6dca5eafcd5f3fe5e5e2dc35d956bc8..7bd77a0d55f216712cd0fd355af574cc10433553 100644 --- a/docs/ch15.md +++ b/docs/ch15.md @@ -150,8 +150,8 @@ The top-level `` tag contains `` and `` tags. The `` tag The DOM API mirrors the tree structure of an HTML document. For each HTML tag in the document, there is a corresponding JavaScript Element object, and for each run of text in the document, there is a corresponding Text object. The Element and Text classes, as well as the Document class itself, are all subclasses of the more general Node class, and Node objects are organized into a tree structure that JavaScript can query and traverse using the DOM API. The DOM representation of this document is the tree pictured in Figure 15-1. -js7e 1501 -Figure 15-1. The tree representation of an HTML document +The tree representation of an HTML document + If you are not already familiar with tree structures in computer programming, it is helpful to know that they borrow terminology from family trees. The node directly above a node is the parent of that node. The nodes one level directly below another node are the children of that node. Nodes at the same level, and with the same parent, are siblings. The set of nodes any number of levels below another node are the descendants of that node. And the parent, grandparent, and all other nodes above a node are the ancestors of that node. The DOM API includes methods for creating new Element and Text nodes, and for inserting them into the document as children of other Element objects. There are also methods for moving elements within the document and for removing them entirely. While a server-side application might produce plain-text output by writing strings with console.log(), a client-side JavaScript application can produce formatted HTML output by building or manipulating the document tree document using the DOM API. @@ -796,9 +796,9 @@ The outerHTML property of an Element is like innerHTML except that its value inc A related Element method is insertAdjacentHTML(), which allows you to insert a string of arbitrary HTML markup “adjacent” to the specified element. The markup is passed as the second argument to this method, and the precise meaning of “adjacent” depends on the value of the first argument. This first argument should be a string with one of the values “beforebegin,” “afterbegin,” “beforeend,” or “afterend.” These values correspond to insertion points that are illustrated in Figure 15-2. -js7e 1502 -Figure 15-2. Insertion points for insertAdjacentHTML() -ELEMENT CONTENT AS PLAIN TEXT +Insertion points for insertAdjacentHTML() + +#### ELEMENT CONTENT AS PLAIN TEXT Sometimes you want to query the content of an element as plain text or to insert plain text into a document (without having to escape the angle brackets and ampersands used in HTML markup). The standard way to do this is with the textContent property: ```js let para = document.querySelector("p"); // First

in the document @@ -1232,8 +1232,8 @@ scrollWidth and scrollHeight return the size of an element’s content area plus ## 15.6 Web Components HTML is a language for document markup and defines a rich set of tags for that purpose. Over the last three decades, it has become a language that is used to describe the user interfaces of web applications, but basic HTML tags such as `` and `