Changing hamburger icon to a X icon | SoloLearn: Learn to code for FREE!


Changing hamburger icon to a X icon

I have used jQuery to change hamburger icon to X icon when clicking on the hamburger icon to view navbar. For some reason it is not working.

1/22/2020 9:43:11 PM


2 Answers

New Answer


This is what you did wrong: Your condition (simplified) is: if(icon == " ||| "){ icon = " X " } if(icon == " X "){ icon = " |||" } Now let's say icon is |||. Then the first if statement changes our icon to X. After that THE CODE IN THE SECOND IF IS EVALUATED BECAUSE THE CONDITION IS TRUE and now we have ||| again. Just use else instead of if.


Thanks Kevin Star. Silly mistake. I have corrected the code. Is this the right way for changing the hamburger icon. Does professional websites also uses something like this ?