When attempting to toggle between the classes 'fa fa-angle-up' and 'fa fa-angle-down', I am encountering issues. The command seems to only work intermittently. Could you please review this code snippet for me? Thank you.
if(iconSubmenu[0].getAttribute('class') == 'fa fa-angle-down'){
iconSubmenu[0].setAttribute('class','fa fa-angle-up')
}
else{
iconSubmenu[0].setAttribute('class','fa fa-angle-down');
}
An error occurred: Uncaught TypeError: Cannot read property 'getAttribute' of undefined
at HTMLLIElement.showSubmenu.onclick