The Pre object represents an HTML <pre> element.
We can access a <pre> element via document.getElementById()
:
var x = document.getElementById("myPre");
Click the button to get the innerHTML of the pre element.
<!DOCTYPE html> <html> <body> <pre id="myPre"> One/*w w w . j av a 2 s. c om*/ Two Three Four Five </pre> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myPre").innerHTML; document.getElementById("demo").innerHTML = x; } </script> </body> </html>