1

in javascript, how can i assign and display a value to tag, so it appears in;

<span id=tag></span>

This needs to be set on the pageload.

i thought it was something like:

<script>
document.getElementById('tag').innerHTML = 0;
</script>
user1022585
  • 13,061
  • 21
  • 55
  • 75

3 Answers3

3

HTML:

<span id="tag"></span>

JS:

<script type="text/javascript">
   window.onload = function(){
     var text = document.createTextNode("0");
     document.getElementById('tag').appendChild(text);
   }
</script>

Although it would be much easier to just do:

<span id="tag">0</span>
driangle
  • 11,601
  • 5
  • 47
  • 54
0

You can try this also

<html>
<head>
<script>
function myFunction() {
    var number = "0";
    document.getElementById("tag").innerHTML = number;
}
</script>
</head>
<body onload="myFunction()">

<h1>"the value is: " <span id="tag"></span></h1>

</body>
</html>
Priyank_Vadi
  • 1,028
  • 10
  • 27
0

Try:

<script>
  window.onload = function(){
        document.getElementById('tag').innerHTML = 0;
  };
</script>
jerjer
  • 8,694
  • 30
  • 36