I created a simple simple javascript program where when I click two buttons that I generate random numbers and the third button allows me to sum the two numbers up and then I can reset.
<html lang="en">
<head>
<title>createTextNode example</title>
</head>
<body>
<button onclick="addTextNode1('Hi!');">N. 1</button>
<button onclick="addTextNode('NO! ');">N. 2</button>
<button onclick="test2('NO!.. ');">A! </button>
<button onclick="myFunction3()">Reset page</button>
<hr />
<p id="p2">1: </p>
<p id="p1">2: </p>
<p id="p3">T: </p>
</body>
</html>
function addTextNode(simple1) {
text1 = Math.floor((Math.random() * 100) + 1);
var newtext = document.createTextNode(text1+" "),
p1 = document.getElementById("p1");
p1.appendChild(newtext);
}
function addTextNode1(simple2) {
text2 = Math.floor((Math.random() * 100) + 1);
var newtext = document.createTextNode(text2+" "),
p2 = document.getElementById("p2");
p2.appendChild(newtext);
}
function myFunction3() {
window.location.reload(true);
}
function test2() {
text5 = text1 + text2;
var newtext5 = document.createTextNode(text5),
p3 = document.getElementById("p3");
p3.appendChild(newtext5);
}
My question is how would I be able to replace the number that was newly displayed by the button by the appendChild method, so that when I click the button again the previous number gets replaced.
Thanks! Much appreciate!
T:
` then `$("p3>span").text(newtext5)` – freedomn-m Jun 25 '17 at 16:28