To achieve this, you can utilize the removeClass
and addClass
functions. Take a look at the code snippet provided below:
function ToggleClasses() {
if ($('#onetwo a').hasClass("fa-bars")) {
$('#onetwo a').removeClass("fa-bars").addClass("fa-eye");
}
else {
$('#onetwo a').removeClass("fa-eye").addClass("fa-bars");
}
if ($('#twothree a').hasClass("fa-bars")) {
$('#twothree a').removeClass("fa-bars").addClass("fa-eye");
}
else {
$('#twothree a').removeClass("fa-eye").addClass("fa-bars");
}
}
$('#onetwo').click(function () {
ToggleClasses();
});
$('#twothree').click(function () {
ToggleClasses();
});
Alternatively, you can use the following solution:
function ToggleClasses() {
$('#onetwo a').toggleClass("fa-bars fa-eye");
//$('#twothree a').toggleClass("fa-bars fa-eye"); Commented out as requested by @OP
}
If the requirement is to swap classes only when the left link is clicked, then the code related to $('#twothree a')
should be commented.