javascript - How to use addClass() to prepend the class in the element's class list -
i hav div in html
<button id="abc" class="btn btn-primary btn-block"></button>
i need add class 'alert-danger' on mouseover. used following code
$(document).on("mouseover","#abc",function() { $(this).addclass("alert-danger"); });
this works fine , appends class @ end of class list below
<button id="abc" class="btn btn-primary btn-block alert-danger"></button>
but problem 'btn' , 'alert-danger' classes have common css rules. 'btn' takes priority (as first in list) , disables rules of 'alert-danger'.so button should 'alert-danger' class first in classlist.
<button id="abc" class="alert-danger btn btn-primary btn-block"></button> // requirement
how modify addclass() in order prepend class instead of appending it.
an alternative requirement.
you can mark !important
css property in alert-danger
class, prioritize css effect per requirement.
check fiddle demo.
Comments
Post a Comment