So...
I have this Icon that I am using, from ion icons. I want to add a jquery that when the user clicks the icon it changes to another one. But the issue is, it uses the attribute name to target the icon.
<a class="mobile-nav-icon js--nav-icon"><ion-icon name="menu-outline"></ion-icon></a>
I want to change the name to the other type of icon
<a class="mobile-nav-icon js--nav-icon"><ion-icon name="close-outline"></ion-icon></a>
How can I target the name attribute? I tried the bellow, following the hasClass, addClass, removeClass logic but didnt work.
$('.js--nav-icon').click(function(){
var nav = $('.js--main-nav');
var icon = $('.js--nav-icon ion-icon');
nav.slideToggle(200);
if (icon.hasName('menu-outline')){
icon.addName('close-outline');
icon.removeName('menu-outline');
} else {
icon.addName('menu-outline');
icon.removeName('close-outline');
}});
Im quite new at Web Dev.