0

I have created a function that has the capability to copy the specific data in each table cells but my problem is that it cannot be accessed after the page is loaded when I put it in $(window).load(function() {}); and if I also put it in $(document).ready(function () {});, some of the table cells is not having the result I want. I'm able to solve my problem by creating the function in both window.load and document.ready but it's not what I want since it's a bit space consuming and not a good coding practice. How can I achieve a result somewhat like this.

$(document).ready(function () {
   myCreatedFunction();
});
$(window).load(function() {
   myCreatedFunction();
});
//and somewhere in the page in which can be accessed by both methods

var myCreatedFunction = function(){
    //some other actions
}
Eem Jee
  • 899
  • 1
  • 21
  • 46
  • Your code should work, unless the page has already loaded, in which case the function isn't hoisted, so it won't be declared by the time you try to call it - either declare it up above, or use a function declaration instead – CertainPerformance Jan 08 '20 at 04:30
  • @CertainPerformance Thanks for that one. It solved my problem. But it's not similar to your tagged duplicate question. Thanks. – Eem Jee Jan 08 '20 at 05:50

0 Answers0