javascriptdom

javascript show variable in html


I'm trying to make a money display for a form which I am making, now I found this script on the web: http://jsfiddle.net/QQGfc/ And I'm trying to implement it into my code like this: (but it's not displaying the text.)

</script>

<script type="text/javascript">
document.getElementById("MyEdit").innerHTML = "My new text!";
</script>

With this in the body

<?php
include'includes/header.php'; 
include'includes/slider.php'; //carousel
?>


<h2>Contact Information</h2>


<div id="MyEdit">
    This text will change
</div>

Ay idea whats going wrong?


Solution

  • You imply that the JavaScript is in the <head>.

    When it runs, the <body> hasn't been parsed, so the element you are trying to modify does not exist.

    Either: