jQuery Style How to - Set child CSS attribute








Question

We would like to know how to set child CSS attribute.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.4.2.js'></script>
<script type='text/javascript'>
$(function(){<!--   www. j av a 2 s .c o  m-->
    $('#bob').children('.divTitle').css('background-color', '#0f0');
});
</script>
</head>
<body>
  <div id="bob">
    <div class="divTitle">
      <a href="#">
        <h1>Title</h1>
      </a>
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: