Get Pre Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Pre

Introduction

The Pre object represents an HTML <pre> element.

You can access a <pre> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<pre id="myPre">
This is a test. //  w w w. ja  v a  2  s.c  o m
This is a test. 
This is a test.
</pre>

<button onclick="myFunction()">get the innerHTML of the pre element</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myPre").innerHTML;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials