Skip to Main Content
Professional JavaScript
book

Professional JavaScript

by Hugo Di Francesco, Siyuan Gao, Vinicius Isola, Philip Kirkbride
September 2019
Intermediate to advanced content levelIntermediate to advanced
664 pages
11h 42m
English
Packt Publishing
Content preview from Professional JavaScript

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 ...
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.
Start your free trial

You might also like

Professional JavaScript for Web Developers, 4th Edition

Professional JavaScript for Web Developers, 4th Edition

Matt Frisbie
Speaking JavaScript

Speaking JavaScript

Axel Rauschmayer
JavaScript

JavaScript

T. J. Crowder

Publisher Resources

ISBN: 9781838820213Other