<p1 id="myDIV">Para #1 Hello! Click the button on top of me...</p>
<p2 id="urDIV">Para #2...</p>
function swapFunction() {
var x = document.getElementById("p1").innerText;
var y = document.getElementById("p2").innerText;
getElementById
does as it's name implies;
Get an Element by it's ID.
Your ID's are
myDIV and
urDIV, and not p1 and p2.
The text of the first paragraph reads to
Hello! Click the button on top of me but there is no button.
The javascript you have have on the page is not wrapped within a
script
tag. so it is just going to be rendered as text on the page.
In this touched-up version, I also did a little re-naming so that variables are named with some clue as to what they actually are as opposed to x & y
<button onclick="swapFunction()">Button</button>
<p id="para1">Para #1 Hello! Click the button on top of me...<br>
<p id="para2">Para #2...
<script type="text/javascript">
function swapFunction() {
var para1 = document.getElementById("para1");
var para2 = document.getElementById("para2");
var content1 = para1.innerText;
var content2 = para2.innerText;
para1.innerText = content2;
para2.innerText = content1;
}
</script>