jQuery Style How to - Change text color








Question

We would like to know how to change text color.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-2.0.2.js'></script>
<style type='text/css'>
.class {<!-- w  ww .j av  a  2s  .c o  m-->
  width: 100px;
  height: 200px;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $('.class').each(function() {
      $(this).css('color','blue');
    });
});
</script>
</head>
<body>
  <div class="class">text</div>
  <div class="class">text</div>
  <div class="class">text</div>
</body>
</html>

The code above is rendered as follows: