0

So i have a webpart where some very smart people have hardcoded the number of items to show... So i've insert some javascript in a script editor to show more items (since those smart people just add "style= display: none" on the items 3 and above... ). But my problem is that the script isn't executed everytime, sometimes i have to refresh the page to make it work. And i wait for the document to be fully loaded before doing my stuff... here's what my code looks like:

<script>
$(window).load(function(){

    $(".Merck_OrgLocUpcomingEvents_wrapper").each(function(){
        $(this).find("li").each(function(){
           $(this).attr("style", " ");});
     });
});
</script>

So this works but not everytime. I don't know why, isn't it because of cache? How can i fix it and make it work everytime i load the page? I can't edit the webpar's code.

  • try using document.ready instead of window.load. Specify type="javascript". – Niranjan Kulkarni Dec 11 '15 at 9:59
  • @NiranjanKulkarni Hi Niran. I did try it but it doesn't change a lot. The execution of the script is still random with document.ready – imaguest Dec 11 '15 at 10:00
  • 1
    jQuery(document).ready(function() { ExecuteOrDelayUntilScriptLoaded(myfunction, "sp.js"); }); – Niranjan Kulkarni Dec 11 '15 at 10:01
  • can you please place your scripteditor webpart after the main webpart and try.? – Karthik Jaganathan Dec 11 '15 at 10:21
0

try using following code for sharepoint 2013,

jQuery(document).ready(function() {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', functionName);
});

and for sharepoint 2010,

jQuery(document).ready(function() {
 ExecuteOrDelayUntilScriptLoaded(functionName, "sp.js");
});

What is that Id ".Merck_OrgLocUpcomingEvents_wrapper" about??

  • The app itself adds some class's names. I will try your way thank you. – imaguest Dec 11 '15 at 10:11
  • Nope, it doesn't work. I execute the code in a script editor. Is it the problem? – imaguest Dec 11 '15 at 10:17
  • Try executing the same code in content editor webpart. – Niranjan Kulkarni Dec 11 '15 at 10:28
  • Try using, $('this').css('display','block'); – Niranjan Kulkarni Dec 11 '15 at 10:33

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.