I have a variable declared:
var recent;
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 thisVar:
function detachVariable(thisDiv, thisVar, fileName) {
//Check if this section is visible:
if($(thisDiv + " li").length > 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);
}
}
}
My click function:
$("#site-nav .nav1").on("click", function (event) {
detachVariable("#recent", "recent", "recent.php");
event.preventDefault();
});
Is there a way I can pass my variable into the function?
If I understood correctly.. all you have to do is remove the quotes around
recent.. see below,