jQuery Selectors: Select elements of a specific class

This entry is part 5 of 33 in the series jQuery Selectors

The example here will select a <ul> element with a class=’rock’.

So only the second list, American Rock is selected.

<!DOCTYPE html>
<head lang='en'>
    <meta charset='UTF-8'>
    <script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
        $(function () {
            $('ul.rock').css('color', 'navy');

<h4>British Pop</h4>
    <li>Cold Play</li>
    <li>Depeche Mode</li>

<h4>American Rock</h4>
<ul class='rock'>
    <li>Linkin Park</li>

Series Navigation<< jQuery Selectors: Class and ID selectors
jQuery Selectors: Appending a li to an ul element >>