Appendix

About

This section is included to assist the students to perform the activities in the book. It includes detailed steps that are to be performed by the students to achieve the objectives of the activities.

Chapter 1: JavaScript, HTML, and the DOM

Activity 1: Extracting Data from a Page

Solution:

  1. Initialize a variable to store the entire content of the CSV:

    var csv = 'name,price,unit\n';

  2. Query the DOM to find all the elements that represent each product. Notice how we wrap the HTMLCollection instance returned in Array.from so that we can handle it like a normal array:

    var elements = Array.from(document.getElementsByClassName('item'));

  3. Iterate over each element found:

    elements.forEach((el) => {});

  4. Inside the closure, using the ...

Get Professional JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.