0

I don't understand something. I have a js code in the $(document).ready() function.

I got:

function functionTest() {
    var elem = document.getElementById("MSOZoneCell_WebPartWPQ2");
    if (elem != null) {
        var dummyevent = new Array();
        dummyevent["target"] = elem;
        dummyevent["srcElement"] = elem;
        elem.parentNode.click();
        WpClick(dummyevent);
}

$(document).ready(function () {
    functionTest();
}

if i execute the function in the js console, it work.

I try:

setInterval(functionTest, 1000);

and the code works but i don't want to use an interval, cause of the "click".

Why is the code not execute the way i want it ?

I have an another code with the same problemes:

$("myClass").css("color", "#a778ae")
1

2010 or 2013? You should look in to ExecuteOrDelayUntilScriptLoaded or SP.SOD.executeFunc depending on version:

SharePoint 2013 Code:

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);

function sharePointReady() {
   alert("Ready");
}

SharePoint 2010 Code:

ExecuteOrDelayUntilScriptLoaded(sharePointReady, "sp.js");

function sharePointReady() {
   alert("Ready");
}

Source: http://www.mahmoudfarhat.net/post/2013/03/23/SharePoint-2013-ExecuteOrDelayUntilScriptLoaded-not-executing-after-page-publish.aspx

| improve this answer | |
  • That's work for $("myClass").css("color", "#a778ae") but it doesn't for the other function. The function is loaded (console.log("function !!!")) but it doesn't affect anything. – Sancho May 28 '14 at 9:12
  • I put a setTimeout(myFunction, 2000) ... it work – Sancho May 28 '14 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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