Passing a variable to a function
<p>I have a variable declared:</p>

<pre><code>var recent;
</code></pre>

<p>And I wrote a function which needs the variable passed into it. However, I believe what is happening is the variable is being passed as a string. The var is represented by <code>thisVar</code>:</p>

<pre><code>function detachVariable(thisDiv, thisVar, fileName) {

    //Check if this section is visible:
    if($(thisDiv + " li").length &gt; 0) {
        $(thisDiv).prepend(thisVar);
    } else {

        //If variable does not have content stored, store it:
        if(thisVar === undefined) {

            $("#site-nav li a").parents().removeClass("nav-active");
            $(this).addClass("nav-active");
            $(thisDiv + " ul.top-level").load('assets/includes/' + thisFile, function () {
                $(this).show().siblings().hide();
                ajaxAudioController();
            });

            //If variable has content, show it:
        } else {
            $("#site-nav li a").parents().removeClass("nav-active");
            $(this).addClass("nav-active");
            $(thisDiv).prepend(thisVar);
        }
    }

}
</code></pre>

<p>My click function:</p>

<pre><code>$("#site-nav .nav1").on("click", function (event) {
    detachVariable("#recent", "recent", "recent.php");
    event.preventDefault();
});
</code></pre>

<p>Is there a way I can pass my variable into the function?</p>
