【发布时间】:2017-01-07 06:42:33
【问题描述】:
谁知道为什么这行不通:
$( "p p" ).each(function() {
$(this).css("color", "green");
});
以及“p > p”,或任何带有嵌套段落元素的东西。虽然可以使用 div 和其他元素
例如检查这个:
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
alert('length='+$('p p').length); // 0
</script>
<div style="border:1px solid;">
<p>The first paragraph in div.</p>
<p>The second paragraph in div (and the 2nd child in this div).</p>
<p>
<span>Span within p (WILL BE fount as "p > span")</span>
<p>P within p (1).</p>
<span>Span within p (will NOT be fount as "p > span")</span>
<p>P within p (2).</p>
</p>
</div>
<p>
<span>Span within p (WILL BE fount as "p > span")</span>
<p>P within p (1).</p>
<span>Span within p (will NOT be fount as "p > span")</span>
【问题讨论】:
-
你不能嵌套
<p>元素
标签: jquery jquery-selectors nested paragraphs