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.

4
  • try using document.ready instead of window.load. Specify type="javascript". Commented Dec 11, 2015 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 Commented Dec 11, 2015 at 10:00
  • 1
    jQuery(document).ready(function() { ExecuteOrDelayUntilScriptLoaded(myfunction, "sp.js"); }); Commented Dec 11, 2015 at 10:01
  • can you please place your scripteditor webpart after the main webpart and try.? Commented Dec 11, 2015 at 10:21

1 Answer 1

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??

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

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.