javascript - Passing a variable to a function -
i have variable declared:
var recent; and wrote function needs variable passed it. however, believe happening variable being passed string. var represented thisvar:
function detachvariable(thisdiv, thisvar, filename) { //check if section visible: if($(thisdiv + " li").length > 0) { $(thisdiv).prepend(thisvar); } else { //if variable 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 way can pass variable function?
if understood correctly.. have remove quotes around recent.. see below,
detachvariable("#recent", recent, "recent.php"); //removed quotes
Comments
Post a Comment