【发布时间】:2014-09-02 16:05:22
【问题描述】:
我想根据父项的“id”以及其中一个子项的“类”来选择一个页面元素。这在子元素是 span 元素时有效,但在它是 div 时失败。
如何选择下面的特定 #testDiv .highlightme 项?
<script>
$(document).ready(function(){
$('#testSPAN .highlightme').css("background-color","yellow");
$('#testDIV .highlightme').css("background-color","blue");
});
</script>
<p id="testSPAN">
<span class="highlightme">
This should highlight, and does. Good.
</span>
</p>
<p id="testDIV">
<div class="highlightme">
This should highlight, but doesn't because it's in a div.
</div>
</p>
【问题讨论】: