Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<div id="main">
</div>
 
let main = document.getElementById('main');
fetch('https://mdn.github.io/fetch-examples/fetch-text/page1.txt')
.then(
    r => r.text().then(data => {
            main.innerHTML = data;
      let h = main.getElementsByTagName('h2')
            alert(h[0].textContent);
    })
);
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers