javascript - This jQuery, Moment.js script won't display in SharePoint Online script editor web part, any ideas why? -


I have set up a script editor Web part in my SharePoint online account. The results show that when I am Page Edit , but not when Browsing page

Here's the script I'm using:

  & lt; H3 & gt; You are married: & lt; Span id = "married" & gt; & Lt; / Span & gt; & Lt; / H3 & gt; & Lt; H3 & gt; Adam was born: & lt; Span id = "adamborn" & gt; & Lt; / Span & gt; & Lt; / H3 & gt; & Lt; Script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Script src = "https://mysite.sharepoint.com/tech/Scripts/moment-with-langs.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; Function SetMoments () {Wedding = $ ('# Married'), Date = Moment ("1955-12-05", "YYYY-MM-DD"), Update = function () {married.html (date. FromNow ()); }; Updates(); Var adamBorn = $ ('# adamBorn'), date = moment ("1992-06-14", "YYYY-MM-DD"), update = function () {adamBorn.html (date.fromNow ()); }; Updates(); }; _spBodyOnLoadFunctionNames.push ("setMoments"); & Lt; / Script & gt;   

I also tried to use the document. Already, but while browsing the page the results are still not displayed.

To ensure this part of the code, warnings () Tried to debug to setMoments () before? Can be reached at some point?

In addition, your code can be simplified:

  & lt; Script & gt; $ ('# Married'). Html (moment ("1951-12-05", "YYYY-MM-DD"). FromNow ()); $ ('#edembern'). Html (moment ("1992-06-14", "YYYY-MM-DD"). FromNow ()); & Lt; / Script & gt;   

Because your script is after both fields, then there is no need to use $ (documen). or _spBodyOnLoadFunctionNames .

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -