I tried to switch the class from an i
tag. First I tried it by using Jquery UI's switchClass
like this:
$( "#sidenavIcon" ).switchClass('fa-angle-double-right', 'fa-angle-double-left');
This was not working. I discovered that someone else also had a problem with switchClass
and he was adviced to use removeClass
and addClass
instead, which worked for him.
However, for me it does not work, and I am confused now.
$(document).ready(
function() {
$("#sidenav").on("click", function() {
$("#sidenavIcon").addClass('fa-angle-double-right').removeClass('fa-angle-double-left');
});
}
);
#sidenav {
background-color: #333333;
color: white;
height: 100vh;
width: 10vw;
position: relative;
}
#sidenav:hover {
cursor: pointer;
}
#sidenavIconWrap {
font-size: 50px;
color: white;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#sidenavIcon {
color: white;
font-size: 20px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="sidenav">
<div id="sidenavIconWrap">
<i id=sidenavIcon" class="fa fa-angle-double-left" aria-hidden="true"></i>
</div>
</div>
UPDATE:
It was indeed because of the missing "
. I trusted PhpStorm to find this and point it out... I learned: never trust your IDE, even if you have a expensive one.