title: How do I run a jQuery function that is attached to a specific element on page load?
body: <h2>My Issue</h2>
  <p>First of all, I am very new to jQuery, so I'm sure this is super simple but I really don't know how to do it. I currently have a jQuery function I wrote that returns the scroll position of a specific element and applies that value as a percent height for a progress bar elsewhere on the page. <em>See below:</em></p>
  <pre class="lang-js prettyprint-override"><code>$(&quot;.contentOuter&quot;).scroll(function() {
     var h = $(&quot;.content&quot;).height(); //the total height of the element to be scrolled
     var vh = window.innerHeight - 96; //the height of the viewbox I am scrolling in
     var sp = (this.scrollTop / (h - vh)) * 100; //the scroll position (my problem piece)
     var spb = $(&quot;.progressLineFill&quot;); //the progress bar element
     spb.height(sp + &quot;%&quot;); //setting the height of the progress bar
  });
  </code></pre>
  <p>I want to run this same function as soon as the page is loaded (just in case the element is already scrolled a little) but because I have included <code>this.scrollTop</code> I don't know how to translate that. I have tried setting a variable to replace the <code>this</code> in <code>this.scrollTop</code> but it seems to completely break everything. <em>See below:</em></p>
  <pre class="lang-js prettyprint-override"><code>var $elem = $(&quot;.contentOuter&quot;); //new variable to replace the need for &quot;this&quot;
  
  $(&quot;.contentOuter&quot;).scroll(function() {
     var h = $(&quot;.content&quot;).height();
     var vh = window.innerHeight - 96;
     var sp = ($elem.scrollTop / (h - vh)) * 100; //the new variable applied
     console.log(sp);
     var spb = $(&quot;.progressLineFill&quot;);
     spb.height(sp + &quot;%&quot;);
  });
  </code></pre>
  <p>I tried logging the value of <code>sp</code> (my scroll position variable) and I just get &quot;NaN&quot; in this configuration. Again, I am really inexperienced with jQuery.</p>
  <h2>My Goal</h2>
  <p>I would like to isolate this function and be able to call it, both on scroll and on load.</p>
  <h2>Conclusion</h2>
  <p>Again, I know this is probably super simple and I would love any suggestions!</p>
  <p><em>If I was unclear about anything, please let me know and I will update the question.</em></p>