p { margin: 8px; font-size:16px; }
.selected { color:blue; }
.highlight { background:yellow; }
<script src="https://code.jquery.com/jquery-latest.js"></script>
$("p").last().addClass("selected");
p { margin: 8px; font-size:16px; }
.highlight { background:yellow; }
<script src="https://code.jquery.com/jquery-latest.js"></script>
$("p:last").addClass("selected highlight");
div { background: white; }
.red { background: red; }
.red.green { background: green; }
<script src="https://code.jquery.com/jquery-latest.js"></script>
<div>This div should be white</div>
<div class="red">This div will be green because it now has the "green" and "red" classes.
It would be red if the addClass function failed.</div>
<div>This div should be white</div>
<p>There are zero green divs</p>
$("div").addClass(function(index, currentClass) {
if ( currentClass === "red" ) {
$("p").text("There is one green div");