I have this javascript file:
var moment = require("moment")
var structuredDate = moment(Date()).format("LLLL")
And i wanted to change a <div>
in html with the date.
I tried this:
<script type="text/javascript" src="bscript.js" async defer></script>
Welcome to my website<br>
Today is: <div id="date"></div>
<script>
const date = document.getElementById("date")
date.innerHTML=StructuredDate
</script>
But it is not working.
I use Browserify to bundle npm packages.
3
Answers
It should
structuredDate
notStructuredDate
.date.innerHTML = structuredDate;
Main thing is that you have used the capital ‘S’ for the variable inside the tag js content. change that to
date.innerHTML = structureDate
And after that, you will see that undefined in the place where you need to see your date. Just copy and paste the following to set the date in that js file.
let today = new Date().toLocaleDateString()
var structuredDate = today
This will provide you with the following output. I think that is your required output too.
Output of the code
I think your code is working with some changes like this:
NOTE: This method is just applied only to client-side