I'm having incredible difficulty attempting to make a jQuery script run when a page is published. I have utilized a multitude of variants of ExecuteOrDelayUntilScriptLoaded and SP.SOD functions to no avail. Everything always works in Edit Mode, but never during Display. As I have publishing features turned on, whenever I debug on a published page I can see that SP.js is actually already loaded regardless if my script calls for it or not. I am all out of ideas as to why this does not run. Please look at one iteration of the code below.

$(document).ready(function () {
    SP.SOD.executeOrDelayUntilScriptLoaded(newQuick, "SP.js");
    function newQuick() {
        var context = SP.ClientContext.get_current();
        var parent = $("#zz12_V4QuickLaunchMenu > ul > li:has('ul')");
        parent.find("span.menu-item-text:first").append("&nbsp; &nbsp;<i class='fa fa-angle-down' aria-hidden='true'></i>");
        parent.closest("li").find("> ul").hide();

        var childUL = $(this).closest("li").find("> ul");
        var isVisible = childUL.is(":visible");

        if (isVisible) {
        else {



If it helps, this is how the code is referenced in my custom masterpage:

 <!--SPM:<SharePoint:CssRegistration runat="server" ID="CssRegistration1" Name="&lt;% $SPUrl:~sitecollection/_catalogs/masterpage/drkBlue/css/drkblue.css %&gt;" after="corev15.css" />-->
        <!--SPM:<SharePoint:ScriptLink runat="server" ID="jQuery" Language="javascript" Name="~sitecollection/_catalogs/masterpage/drkBlue/js/jquery-3.1.1.min.js" OnDemand="false" />-->
        <!--SPM:<SharePoint:ScriptLink runat="server" ID="accordion" Language="javascript" Name="~sitecollection/_catalogs/masterpage/drkBlue/js/accordion.js" OnDemand="false" />-->
        <link rel="stylesheet" href="/ecms/_catalogs/masterpage/drkBlue/font/font-awesome/css/font-awesome.min.css"/>
  • Does MDS enabled on your site? Jan 4, 2017 at 12:53
  • No. Which is another reason why I don't understand that the script is not loading on published pages. Jan 4, 2017 at 13:08

1 Answer 1


Upon further inspection, I figured out what the issue was for me. Quicklaunch in SharePoint has two different IDs for edit mode and display mode. Adjusting the ID for the jQuery selector resolved the issue.

Thanks to everyone for their continued help and input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.