1

Thanks for this article Enable like function from catalog page via javascript object model - improve this? is very useful and its working on my page, but i need your help, i am calling rest api function to read the first 3 items of the list and i am trying to integrate the like functions code in my main code and to do that i have insert this: < div id='idnumb' >"+itemid+"< / div > in the ajax code to read id's value of each item and i am trying to set the id value to the variable as var sItem = $("div#idnumb").text(); but i have a main problem that i need to set the sItem value after the load of the list contents ( title, id , description content) ??? i tried many workaround steps but still cannot read the id of each item.

First question, this is a good solution to convert the like function code to read dynamic item value, by using $("div#idnumb").text()

and if not, please suggestion another solutions

  • The div has id "idnumb" but not using $('div#idnumb') in jQuery? – YogaPanda Apr 10 '18 at 20:54
  • Yes sorry i have used $('div#idnumb').text() i will update the question – HaSS Apr 11 '18 at 5:49
  • The issue is when add any variable for example var itemid = 1; in the $(document).ready ... the like function is not reading this variable to define item id for the like..... please check this article sharepoint.stackexchange.com/questions/134497/… and let me know how i can add the variable sItem declaration on load of the page – HaSS Apr 11 '18 at 7:05
  • Is it a timing issue the code should run after page fully loaded? – YogaPanda Apr 11 '18 at 20:48
  • Yes its a timing issue i have used $(document).ready(function () { setTimeout(function(){ var parItem = $('div#idnumb').text() },100); }); but how i can reinitialize the code of the like script function and set parItem = sItem in that code [ sharepoint.stackexchange.com/questions/134497/… ] please help me – HaSS Apr 12 '18 at 12:14
0

After lots of research, I use window.bind instead of document.ready to run script after the page loads.

Sample code as below:

$(window).bind("load", function() {
 // Your codes here     
});
  • This is the updated code: $(window).bind("load", function() { setTimeout(function(){ // Your codes here }, 200); }); – HaSS Apr 23 '18 at 12:49

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.