Note that there are some explanatory texts on larger screens.

plurals
  1. POfunction scope in jQuery
    primarykey
    data
    text
    <p>I have this code in <code>&lt;script&gt;</code> tags at the top of my HTML file.</p> <pre><code> $(document).ready(function() { $('#scrollbar1').tinyscrollbar(); $('a.jqtree_common').click(updateScrollbar()); }); $(function updateScrollbar() { var oScrollbar = $('#scrollbar1'); oScrollbar.tinyscrollbar(); oScrollbar.tinyscrollbar_update(); $('a.jqtree_common').click(updateScrollbar()); }); </code></pre> <p>But for some reason when I run this, it says <code>updateScrollbar()</code> is undefined within <code>(document).ready</code>. When I try to define <code>updateScrollBar()</code> inside of <code>(document).ready</code> then <code>updateScrollBar()</code> gets caught in some kind of endless loop.</p> <p>My question is twofold:</p> <ol> <li>What can I do to make <code>updateScrollBar()</code> defined within the scope of <code>(document).ready</code>?</li> <li>Is there a better way to assign this function to the <code>'a.jqtree_common'</code> elements? They are created dynamically at runtime, and modified as the webpage is used. I want the function to run every time one of them is clicked.</li> </ol> <p>I'm using tiny <a href="http://baijs.nl/tinyscrollbar/" rel="nofollow">scrollbar</a> and <a href="http://mbraak.github.io/jqTree/#jqtree" rel="nofollow">jqtree</a></p> <p>EDIT: I want the <code>$('a.jqtree_common').click(updateScrollbar);</code> assignment to be made every time the scrollbar is updated, since I believe clicking on a <code>'a.jqtree_common'</code> element creates more <code>'a.jqtree_common'</code> elements.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload