jQuery Style How to - Change style based on the class inside








Question

We would like to know how to change style based on the class inside.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.2.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--   w  w w .  ja v a2s.  c  o  m-->
    $(".blockcontent .advertisement").parent().css({background: "red"});
});
</script>
</head>
<body>
  <div class="defaultblock">
    <div class="blockcontent">
      <div id="group-id-tids-11" class="advertisement">Inner content</div>
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: