+ 3
JavaScript inside html
How can I display a JavaScript variable inside an html element? I wanted a paragraph <p> to show var x = value, and I need it to be dynamic so I can change var x’s value but still be shown
3 ответов
+ 5
<p id="test"></p>
<script>
window.onload=function(){
var x=10;
var test=document.getElementById("test").innerHTML =x;
}
</script>
+ 4
<p>
var x = <span id=x></span>
</p>
<script>
var x = document.getElementById('x');
// ...do what you want with x
</script>
+ 1
Shudarshan Rai that code worked like a charm. thanks