Why var value not show in id element ?
I try many time but not work , How can i do that ?
<script>
var xxxx = "test";
//alert(xxxx);
document.getElementById("here").innerHTML = xxxx;
</script>
<span id="here"></span>
Why var value not show in id element ?
I try many time but not work , How can i do that ?
<script>
var xxxx = "test";
//alert(xxxx);
document.getElementById("here").innerHTML = xxxx;
</script>
<span id="here"></span>
Try this:
<span id="here"></span> <script> var xxxx = "test"; //alert(xxxx); document.getElementById("here").innerHTML = xxxx; </script>
And have a look at Why does jQuery or a DOM method such as getElementById not find the element?, as @Teemu suggests.
Basically, you're trying to reference the element here
before it's defined. Put your script
tags under your span
tag and it should work.