Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I can't seem to put the value of a variable with innerHTML

my js script :

var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); 
var yyyy = today.getFullYear();

today = mm + '/' + dd + '/' + yyyy;


document.getElementById("heure").innerHTML = today; 

my html code :

<!DOCTYPE html>
<html lang="fr">
<head>
   <script src="../js/index.js" type="text/javascript"></script>
</head>
<body>
   <p>
       Il est :    <span id="heure"></span>
   </p>
   <p>
       et vous etes actuellement sur mon site, quel honneur.
   </p>
</body>
</html>

the alert to test the javascript file work, document.write(today) work, realy i dont understand…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try using script tag at the end of body, most probably the issue here is that, the script is loading before DOM, because of which it cannot recognise span tag

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading