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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
onload is not what you need (it won’t even work), you need to be executing this on
document.readyI think you’re mixing jQuery and JavaScript, try using
document.readyin a script block.First we’ll give your span an ID
Then we can do:
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: