title: Why is my onclick event throwing undefined?
body: <p>I have the following button:</p>
  
  <pre><code>&lt;input type="button" onclick="printDiv('print-content')" value="print a div!"/&gt;
  </code></pre>
  
  <p>And the following JavaScript right below:</p>
  
  <pre><code>&lt;script&gt;
  $(function() {
    function printDiv(divName) {
     alert('s')
       var printContents = document.getElementById(divName).innerHTML
       w=window.open()
       w.document.write(printContents)
       w.print()
       w.close()
    }
  })
  &lt;/script&gt;
  </code></pre>
  
  <p>When I click printDiv, though I get the following error:</p>
  
  <blockquote>
    <p>Uncaught ReferenceError: printDiv is not defined payment-history:398
    onclick</p>
  </blockquote>
  
  <p>I really don't get it.</p>