pythonic pythonic - 4 months ago 7
CSS Question

Is it possible to change the class name of a div element

I have something like shown below.

<div class="alert alert-info" style="width:224px">
<strong>Info!</strong> This is a netural alert
</div>


Through javascript or jquery, at certain condition, I want to change the class of that div element from
alert alert-info
to
alert alert-success
. Is that possible? And if so, how?

Answer

Change class with condition, Use the following sample

$('.alert').click(function(){
if(0==0)//your condition goes here
{
  $(this).removeClass('alert-info').addClass('alert-success');
}else{
  $(this).removeClass('alert-success').addClass('alert-info');
}
});