I'm trying to put the results of this simple JavaScript into a div, where i put the results anywhere on the webpage
Example script:
var numOne=25
, numTwo=14
, res
;
res = numOne - numTwo;
document.write(" " + res + "");
I don't have a clue how to set this up in the script
It is best if it already exists in the HTML and has an id, as shown below.
document.getElementById
to access that element, and put the result into its innerText
Here is an example.
var numOne = 25,
numTwo = 14,
res;
res = numOne - numTwo;
document.getElementById("result").innerText = res;
<div id="result"></div>