By Id
<div id="my-title">My Title</div>const titleEl = document.getElementById('my-title');or
const titleEl = document.querySelector('#my-title');NOTE: Check querySelector browser support or can i use querySelector.
Get the text of element
console.log(titleEl.text);By Class
<div class="row">Row 1</div><div class="row">Row 2</div>const rows = document.getElementsByClassName('row');or
const rows = document.querySelector('.row');Loop through all elements
rows.forEach(el => { console.log(el.text);});By Tag
<article>Article 1</article><article>Article 2</article>const articles = document.getElementsByTagName('article');or
const articles = document.querySelector('article');Loop through all elements
articles.forEach(el => { console.log(el.text);});