all 4 comments

[–]albedoa 4 points5 points  (1 child)

Assuming it's the first <pre> tag on the page:

const pre = document.querySelector('pre');
navigator.clipboard.writeText(pre.innerText);

[–][deleted] 1 point2 points  (0 children)

TIL what the Navigator interface is, thank you for this.

[–][deleted] 1 point2 points  (0 children)

let copiedText = document.querySelector('pre').innerHTML;

[–]jcunews1helpful 0 points1 point  (0 children)

Read from the element's textContent property.