I want to set the current time to an Element with momentjs.
<span onload="$(this).text(moment().format('MMMM Do YYYY, h:mm:ss a'));"></span>
What is wrong with it? Nothing is shown.
onload is not what you need (it won't even work), you need to be executing this on document.ready
I think you're mixing jQuery and JavaScript, try using document.ready in a script block.
First we'll give your span an ID
<span id="yourSpan"></span>
Then we can do:
<script type="text/javascript">
$(function () {
$("#yourSpan").text(moment().format('MMMM Do YYYY, h:mm:ss a'));
});
</script>
EDIT: As you've said you want it inline (although it's really bad practice and I'll have to wash my hands after writing it), still add your ID to your span as above, but do this:
<body onload="$('#yourSpan').text(moment().format('MMMM Do YYYY, h:mm:ss a'));">
loadevents are not triggered onspanelements.