I know this is a simple question but I have been playing around with no success. I have the following code
<a id="mute"><i class="icon-volume"></i></a>
I want to be able to toggle the class .icon-volume to .icon-volume-off when clicking.
After anyone who can help! Thanks
WARNING: This is a (relatively) new attribute. Check the compatibility table from Mozilla's Developer Network before you proceed. If IE 9 (or below) is important to you, then this is not the answer you're looking for.
DOM elements have a property called
classList
. The 3 methods you should familiarize yourself with areadd
,remove
, andtoggle
.In your case:
Pretty simple.
Try
See demo here
You could use jQuery
Or you could just add the
icon-volume-off
class and make sure its css takes precedence over theicon-volume
class