jQuery Style How to - Apply style only to a combination of two classes








Question

We would like to know how to apply style only to a combination of two classes.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<style type='text/css'>
.d {<!--from  www.  j a v  a  2  s. c  o m-->
  color: red;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $("[class*='a c']").addClass('d');
});
</script>
</head>
<body>
  <p class="a b c">Hello</p>
  <p class="a b c">Hello</p>
  <p class="a c">Hello</p>
  <p class="a b c">Hello</p>
</body>
</html>

The code above is rendered as follows: