jQuery Style How to - Change CSS attribute








Question

We would like to know how to change CSS attribute.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<style type='text/css'>
div {<!--from   ww w  . j a v  a 2  s. c o  m-->
  color: red;
}

.shown {
  color: blue;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    var thing = $('div')
    thing.addClass('shown');
});
</script>
</head>
<body>
  <div>test</div>
</body>
</html>

The code above is rendered as follows: