Skip to content

Instantly share code, notes, and snippets.

@ross-u
Last active October 9, 2019 12:52
Show Gist options
  • Save ross-u/bc5f6940cad9d98c2c908476412e56dd to your computer and use it in GitHub Desktop.
Save ross-u/bc5f6940cad9d98c2c908476412e56dd to your computer and use it in GitHub Desktop.
JS | DOM - Get The Titles - Exercise

JS | DOM

Get The Titles - Exercise


Task 1

In a new tab navigate to the Hacker News webpage, and open the Chrome Dev console (Command + Option + J).

We will write our JavaScript code in the console.

The anchor links which include the topic names have the class storylink. We can use this to target and select only those elements. We can use the following code:

let titles = document.getElementsByClassName("storylink");

Task 2:

Now create a for loop that prints the innerHTML of each title element


Task 3:

Now create a for loop that iterates over the same items and prints the href link values of each title element. To get the href value of an element you have to use the getAttribute method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment