DOCTYPE HTML html head meta charset utf-8 head body button id jsbutton

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE HTML>
<html>
<head><meta charset="utf-8"></head>
<body>
<button id="jsbutton" onclick="reverseBody()">ChangeBody</button>
<p>11111111</p>
<p>22222222</p>
<p>33333333</p>
<p>44444444</p>
<script type="text/javascript">
function reverseBody()
{
var t = {};
t = document.body.children;
var newT = {};
var z = 0;
for(var i = t.length-1; i>=0; i--)
{
if(t[i].tagName != "SCRIPT" && t[i].tagName != "BUTTON")
{
newT[z] = t[i];
z++;
document.body.removeChild(t[i]);
}
}
for(var i = 0; i < Object.keys(newT).length; i++)
{
document.body.innerHTML += "<"+newT[i].tagName+">"+ newT[i].innerHTML+"</"+newT[i].tagName+">";
}
}
</script>
</body>
</html>