I am trying to run this code to get the elements from the paragraph in my HTML code and display:
<!DOCTYPE html>
<html>
<body>
<p>This is a p element<br>
This is also a p element.<br>
This is also a p element - Click the button to change the background color of all p elements in this document.</p>
<button onclick="myFunction()">Try it</button>
<script>
    function myFunction() {
        win = window.open();
        win.document.open();
        var x = document.getElementsByTagName("p");
        for (var i = 0; i < x.length; i++) {
            win.document.write(document.getElementById(x.item(i).id).innerHTML);
        }
    }
</script>
</body>
</html>
I don't know how, but I keep getting a blank window. Any help?
Thank you.
 
     
    