Most interesting applications of JavaScript involve making changes to the way web pages display in response to user actions.

For example, here is a page that allows a user to solve the FWGC and water jug problems: solve.html.

Using JavaScript to dynamically manipulate web pages requires more understanding of HTML and the associated Document Object Model (DOM).

Here is a simple HTML page:

An HTML page consists of nested elements, with html being the outer-most element.

Nested within the html element are the head and body elements, which themselves have nested elements.

Here is how a browser renders this page: mypage.html.

HTML elements provide the structure and content of web pages.

The nesting structure of elements within an HTML page can be represented by trees.

Shown below is an element tree for mypage.html.

Note that two of the elements, title and h1, also have text associated with them, though they are not shown here.

The W3 Schools HTML Tutorial is a good resource for learning about HTML.

The rendering of the problem solving web page solve.html is shown below on the left.

The layout of this page is achieved by using an HTML table element, whose structure is shown on the right.

The table is 7 rows × 2 columns, with several of the row elements spanning two columns:

Page Rendering Table Structure
Creating tables in HTML usually involves the following elements:
Below is the element structure tree for the layout in solve.html.

Note the tr elements having only one child. These child elements span multiple columns in the table.

When a td or th element needs to span multiple columns, a colspan attribute can be used, like this:
   <td colspan="2" ... >
	
Here is the basic structure of the HTML code for the layout in solve.html:
The Document Object Model (DOM) is a programming interface for HTML and XML (Extensible Markup Language) documents: The DOM provides a representation of the document as a structured group of nodes and objects that have properties and methods.

Essentially, it connects web pages to scripts or programming languages.

According to the DOM, everything in an HTML document is a node:
The HTML DOM views an HTML document as a tree structure called the node tree.

All nodes can be accessed through the tree, and their contents can be modified or deleted, and new elements can be created.

The node tree shown below at the bottom shows the nodes associated with the following mypage.html and the connections between them.

The tree's root is the document node and branches out to the text nodes at the lowest level.

In order to programmatically manipulate DOM nodes with JavaScript, the nodes must be uniquely identified.

This is accomplished in the HTML code with id attributes.

Shown below is the HTML code for the table layout in solve.html with id attributes added.

This example also illustrates the following:
The DOM uses an object-oriented paradigm, with the objects, in this case DOM nodes, having both properties and methods.

Below are some properties of DOM nodes. For each of the following, x is an HTML element node.

Below are some methods attached to DOM nodes.