How can I set up a $.fn. function so it gets executed when called?
<p>I have the following code:</p>

<pre><code>    function init() {
        var $contentButtonPanel: JQuery = $('#content-button-panel')
        $contentButtonPanel
            .find('.arbo .toggle, .collapsible-list li:has(ul) &gt; :first-child, .collapsible-list li:has(ul) &gt; :first-child + span')
            .click(function (event) {
                $(this).toggleBranchOpen();
            });
    }

    $.fn.toggleBranchOpen = function () {
        this.each(function () {
            $(this).closest('li').toggleClass('closed');
        });
        return this;
    };
</code></pre>

<p>When I debug I can see that the $(this).toggleBranchOpen(); line is reached. However the code does not go inside that function. </p>

<p>Is this a problem with the way that toggleBranchOpen is declared? Note that the only time toggleBranchOpen is used is inside of the init function click event. Is it possible for me to move that code into the init and simplify things?</p>
