Chapter 2
Advanced JavaScript Coding
IN THIS CHAPTER
Understanding the DOM
Working with the DOM
Reading data from your web page
Writing to your web page
In the previous chapter, you saw the basics of how to incorporate JavaScript code into a web page. In that chapter, you ran a couple of simple JavaScript programs, using the prompt() function for input, and the alert() function for output. That was a great start, but the whole reason we’re interested in JavaScript is to use it to dynamically alter the data and/or appearance of our web pages. This chapter walks through how JavaScript interfaces with your web pages and shows you how to write JavaScript code to dynamically add, delete, or change content in your website.
The Document Object Model
For JavaScript to have access to the elements in your web page, it needs to know how to find them. The HTML Document Object Model (DOM) provides a standard way of accessing objects placed within a web page. It creates a tree structure that contains every element, attribute, content text, and even CSS3 style contained within a web page. Finding ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access