javascript - Change class of active bootstrap button on hover -
if want change class of bootstrap button on hover jquery, styling of button changes new custom class, add "addclass":
<div id="tile-sort" class="btn-group" data-toggle="buttons"> <label id="sort-hello" class="btn btn-primary btn-xs"> <input type="radio" name="sort-option" value="hello">hello </label> </div>
the below code works:
$('#tile-sort').hover( function() { $('.btn-primary').addclass('sort-hover-nonactive'); }, function() { $('.btn-primary').removeclass('sort-hover-nonactive'); } );
however, if attempt change class of "active" bootstrap button on hover jquery:
<div id="tile-sort" class="btn-group" data-toggle="buttons"> <label id="sort-goodbye" class="btn btn-primary btn-xs active"> <input type="radio" name="sort-option" value="goodbye">goodbye </label> </div>
the below code does not work:
$('#tile-sort').hover( function() { $('.btn-primary.active').addclass('sort-hover-active'); }, function() { $('.btn-primary.active').removeclass('sort-hover-active'); } );
can point me in correct direction class adding/removing happen?
looks issue might coming somewhere else, maybe didn't set !important
on custom css?
i've tried follows:
.sort-hover-active { background-color:red !important; }
edited:
following comments of @jshthornton, edited code more in line bootstrap's native code. here did:
$('#tile-sort').hover( function() { $('#sort-goodbye').removeclass('btn-primary').addclass('btn-danger'); }, function() { $('#sort-goodbye').removeclass('btn-danger').addclass('btn-primary'); } );
this way you're making use of existing bootstrap code instead of applying cumbersome workarounds !important
should preferably avoided, if possible.
Comments
Post a Comment