...

/

How it Works: Querying the Document

How it Works: Querying the Document

In this lesson, we learn the implementation of the previous lesson's exercise. Let's begin!

How it works

Because originally hideandseek.js was empty, including it in index.html did not actually run any JavaScript code.

However, in step three, when you added code to this file it was executed. That is how the output in the below image was created.

You added this code:

Press + to interact
var titles = document.getElementsByTagName('h2');
for (var i = 0; i < titles.length; i++) {
var title = titles[i];
document.write('<h3>' + title.textContent + '</h3>');
}

The key operation is in line one. The document object represents the current document in the browser. ...