Do I have to use tags to switch class styles?

< button type= "button" class= "btn btn-primary" > inventory < span class= "glyphicon glyphicon-sort-by-attributes-alt" > < / button >

want to switch from class="glyphicon glyphicon-sort-by-attributes-alt" to class="glyphicon glyphicon-sort-by-attributes" (expected implementation: click the button to switch between two styles)
can it be achieved directly with toggleClass?

Mar.16,2021

Yes, that is, classNameOne is a default style. If you click, use toggleClassTwo to delete or add the class name according to the situation, and then change the style according to the weight. Then one more word, this kind of thing, you will find out by yourself.


two class names can be used with the following code:

if($('button').hasClass('glyphicon-sort-by-attributes-alt')){
    $('button').add('glyphicon-sort-by-attributes').removeClass('glyphicon-sort-by-attributes-alt')
}
else {
    $('button').add('glyphicon-sort-by-attributes-alt').removeClass('glyphicon-sort-by-attributes')
}
Menu