The innerHTML , innerText , outerHTML , and outerText PropertiesThe innerHTML , innerText , outerHTML , and outerText properties are the basis of much Dynamic HTML, because they enable you to access an HTML element's HTML and text, and change them at runtime. We'll put these properties to work in Chapter 16. Here's an overview of these properties:
You can see the support for these properties in Table 5.27 (note that only innerHTML is supported by the Netscape Navigator, and only in version 6 so far). Table 5.27. The innerHTML , innerText , outerHTML , and outerText Properties
Here's an Internet Explorer example using the innerHTML property that rewrites an <H1> header when you click that header, using the innerHTML property: (Listing 05-14.html on the web site) <HTML> <HEAD> <TITLE>Using the innerHTML Property</TITLE> <SCRIPT LANGUAGE = JavaScript> <!-- function rewriteHeader() { document.all.Header.innerHTML = "Here's a New Header!" } </SCRIPT> </HEAD> <BODY> <H1 ID="Header" ONCLICK="rewriteHeader()">Click Me!</H1> </BODY> </HTML> You can see the results in Figure 5.11, where I've clicked the header to rewrite it. Figure 5.11. Using the innerHTML , innerText , outerHTML , and outerText properties.
We'll see more on these properties in Chapter 16. |