document.querySelectorAll('h1,h2,h3,h4,strong').forEach(function(header) { console.log(' '.repeat(header.tagName.replace('STRONG', 'H5').replace('H', '')) + header.textContent) });