0

HTML Display A JavaScript Variable

How do you do this?

13th Jan 2018, 11:24 PM
YoBoi
3 Respuestas
+ 2
Probably better to use .innerHTML property of html element targeted to display the value of variable: <div id="mydiv">text</div> <input type="button" onclick="myfunc();" value="change content"> <script> var myvalue = 42; function myfunc() { var d = document.getElementById("mydiv"); d.innerHTML = myvalue; } </script>
13th Jan 2018, 11:45 PM
visph
visph - avatar
+ 1
There are different ways to display the content the variable actually has: You can give it out to the console with console.log(variable); write it into an element of the webpage with document.getElementById("info").innerHTML = variable; or give it out into a textfield with document.getElementById("info").value = variable; to name just a few,
13th Jan 2018, 11:45 PM
Rainer Wess
Rainer Wess - avatar
0
you can show it with document.write(variableName);
13th Jan 2018, 11:36 PM
amin charoliya
amin charoliya - avatar