I am creating a simple accordion menu with two ways of navigating.
- By clicking on the step title
- By clicking on "Next / Prev" buttons inside the step.
My js code looks like this:
$(document).ready(function(){
// Click on TITLE
$(".step-title").click(function(){
var this_title = $(this).parents(".step").children(".step-title");
var this_content = $(this).parents(".step").children(".step-content");
var that_title = $(".step-title");
var that_content = $(".step-content");
if (this_title.hasClass("active"))
{
this_title.removeClass("active");
this_content.slideUp(200);
} else {
that_title.removeClass("active");
this_title.addClass("active");
that_content.slideUp(200);
this_content.slideDown(200);
}
});
// Click on BUTTON
$(".save").click(function(){
var this_title = $(this).parents(".step").children(".step-title");
var this_content = $(this).parents(".step").children(".step-content");
var that_title = $(".step-title");
var that_content = $(".step-content");
if (this_title.hasClass("active"))
{
that_title.addClass("active");
this_title.removeClass("active");
that_content.slideDown(200);
this_content.slideUp(200);
}
});
});
As you can see I am reusing the same variables on both functions and hence the root of my question.
** QUESTION ** Is there a way for me to share those variables in multiple functions?
When I take them out of the local scope of the function they don't work.
Thank you for your help.