My goal is to display the 'menu-outline' ionicon on my website until it is clicked, at which point the icon will change to 'close-outline' and vice versa. I am utilizing jQuery for this functionality.
Although I am aware of how to toggle classes, my ionicons are identified by their names rather than classes:
<a class="menu-button js-menu-button"><ion-icon name="menu-outline"></ion-icon></a>
Currently, my jQuery code toggles the menu but doesn't handle the icon switching:
$(".js-menu-button").click(function() {
var nav = $(".js-main-nav");
var icon = $(".js-menu-button ion-icon");
/* appear and disappear */
nav.slideToggle(200);
});
I am wondering if there is a way to toggle the name of the icon or if there is an alternative approach to achieve this effect. Any suggestions would be greatly appreciated. Thank you.