I would really appreciate it if someone could help me refactor this code into a reusable function and show me how to use it. I'm just a beginner, but can see that I'm repeating lots of stuff and I'm sure there's a way to write it better.
I can add html if it's needed.
$("[value=home]").click(function() {
$(currentLink).removeClass("cantclick");
$(current).hide();
$(this).addClass("cantclick");
$("#texts").fadeIn(900);
current = $("#texts");
currentLink = $("[value=home]");
console.log("current is " + current.text() + ".");
});
$("[value=aboutme]").click(function() {
$(currentLink).removeClass("cantclick");
$(current).hide();
$(this).addClass("cantclick")
$("#aboutmetext").fadeIn(900);
current = $("#aboutmetext");
currentLink = $("[value=aboutme]");
console.log("current is " + current.text() + ".");
});
$("[value=tuition]").click(function() {
$(currentLink).removeClass("cantclick");
$(current).hide();
$(this).addClass("cantclick")
$("#tuitiontext").fadeIn(900);
current = $("#tuitiontext");
currentLink = $("[value=tuition]");
console.log("current is " + current.text() + ".");
});
$("[value=consultancy]").click(function() {
$(currentLink).removeClass("cantclick");
$(current).hide();
$(this).addClass("cantclick")
$("#consultancytext").fadeIn(900);
current = $("#consultancytext");
currentLink = $("[value=consultancy]");
console.log("current is " + current.text() + ".");
});