How to toggle between two icons without buttons using boot-strap and jQuery ?
Approach: The approach is to simply add an “on click” event listener to both of the icons and toggle the CSS classes of both the icons using jQuery. These classes are ultimately responsible for displaying a specific icon from the icon library (Fontawesome, in this case). Here, we have used two icons,
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML course.
- One with the class name of “fa-bars” (Menu icon)
- One with the class name of “fa-times” (Cross icon)
Whenever a user will click on the menu icon, its “fa-bars” class will be toggled to “fa-times”, thus the cross icon will be then displayed and vice versa is also true.