JavaScript closure onclick
<p>I saw many examples and tried to follow but none of them would work. So I am finally posting them here. I cannot understand what I am doing wrong.</p>

<p>There is a list of FAQ questions /answers with show/hide feature to answers.</p>

<p>Here is my code without applying closure (this targets only the last question of course)</p>

<pre><code>for(var i = 1; i &lt;= faqCount; i++) {
    question = '#' + i + ' .faq_question';
    answer = '#' + i + ' .faq_answer';
    $(question).click(function () {
        $(answer).toggle();
        $(question).toggleClass('down');
    });
}
</code></pre>

<p>But looking at the other examples I tried to do this but did not work:</p>

<pre><code>var funcs = [];
function createfunc(i) {
    return function() {
        question = '#' + i + ' .faq_question';
        answer = '#' + i + ' .faq_answer';
        $(question).click(function () {
            $(answer).toggle();
            $(question).toggleClass('down');
        }); 
    };
}   
for (var i = 0; i &lt; faqCount; i++) {
    funcs[i] = createfunc(i);
}
for (var j = 1; j &lt; faqCount; j++) {
    funcs[j]();                        
}
</code></pre>

<p>Any help would be appreciated. Thank you.</p>
