Get the HTML content of a <p> element with id="myP"
:
var x = document.getElementById("myP").innerHTML;
Click the button get the HTML content of the p element.
<!DOCTYPE html> <html> <body> <p id="myP">I am a paragraph.</p> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w w w.j a v a 2 s . c o m*/ var x = document.getElementById("myP").innerHTML; document.getElementById("demo").innerHTML = x; } </script> </body> </html>