我试图选择li
列表第二级的所有元素,向它们添加特殊类。我做了几次尝试都没有成功。所以li
我瞄准的元素是喜剧、悲剧和历史下面的水平。
<script type="text/javascript">
$(document).ready(function () {
$('li').next().addClass('special');
});
</script>
<style type="text/css">
.special {
font-style: italic;
}
</style>
<body>
<div id="container">
<h2>Selected Shakespeare Plays</h2>
<ul id="selected-plays" class="clear-after">
<li>Comedies
<ul>
<li>
<a href="/asyoulikeit/">As You Like It</a>
</li>
<li>All's Well That Ends Well</li>
<li>A Midsummer Night's Dream</li>
<li>Twelfth Night</li>
</ul>
</li>
<li>Tragedies
<ul>
<li>
<a href="hamlet.pdf">Hamlet</a>
</li>
<li>Macbeth</li>
<li>Romeo and Juliet</li>
</ul>
</li>
<li>Histories
<ul>
<li>Henry IV (
<a href="mailto:henryiv@king.co.uk">email</a>)
<ul>
<li>Part I</li>
<li>Part II</li>
</ul>
</li>
<li>
<a href="http://www.shakespeare.co.uk/henryv.htm">Henry V</a>
</li>
<li>Richard II</li>
</ul>
</li>
</ul>
</body>