You would just set the .textContent
of the element that it will be shown in to the variable. No hiding/showing of the element is needed because the element’s .textContent
will be empty at first (so it will initially not show anything anyway).
<html>
<head>
<title>Using form data in the page</title>
</head>
<body>
<div>
<input type="text" id="input">
<button onclick="go()">Click</button>
</div>
<div id="show"></div>
<script>
function go() {
let value = document.getElementById('input').value;
document.getElementById('show').textContent = value;
}
</script>
</body>
</html>
14
solved How to display the value of a javascript variable in html? [closed]