...
/How It Works: Adding Actions to the Web Page with JS
How It Works: Adding Actions to the Web Page with JS
In this lesson, we'll understand the workings of the previous lesson's exercise. Let's begin!
We'll cover the following...
We'll cover the following...
HOW IT WORKS
The key to this behavior is the handleClick function you added to index.html in step 3.
When loading a page, the browser recognizes the <script> sections and immediately executes the code within. Here, the <script> contains a function definition and executing the code means that the definition is hoisted into the current page’s JavaScript context. Let’s have a look at what this function does.
1 function handleClick(node) {
2 var value = node.getAttribute('class') || '';
3 value = value === '' ? ...