title: Run JavaScript after page load on WordPress using JQuery
body: <p>I'm new to JS and I'm still trying to understand it all. So I've decided to give myself a few projects so I can learn the syntax.</p>
  <p>I have a chat widget that loads when someone lands on my website. However, I'd like to only run this widget after the page has loaded to improve website performance.</p>
  <p>How do I go about adjusting this script to run only after my WordPress web page has loaded?</p>
  <pre><code>&lt;!--Start of Tawk.to Script--&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
  var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
  (function(){
  var s1=document.createElement(&quot;script&quot;),s0=document.getElementsByTagName(&quot;script&quot;)[0];
  s1.async=true;
  s1.src='https://embed.tawk.to/...../default';
  s1.charset='UTF-8';
  s1.setAttribute('crossorigin','*');
  s0.parentNode.insertBefore(s1,s0);
  })();
  &lt;/script&gt;
  &lt;!--End of Tawk.to Script--&gt;
  </code></pre>
  <p>UPDATED: The widget developer suggested this.</p>
  <pre><code>&lt;!--Start of Tawk.to Script--&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
  var w = window;
  var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
  (function(){
  function l() {
  var s1=document.createElement(&quot;script&quot;),s0=document.getElementsByTagName(&quot;script&quot;)[0];
  s1.async=true;
  s1.src='https://embed.tawk.to/...../default';
  s1.charset='UTF-8';
  s1.setAttribute('crossorigin','*');
  s0.parentNode.insertBefore(s1,s0);
  }
  if (w.attachEvent) {
  w.attachEvent('onload', l);
  } else {
  w.addEventListener('load', l, false);
  }
  })();
  &lt;/script&gt;
  &lt;!--End of Tawk.to Script--&gt;
  </code></pre>