2012-05-24 61 views
0

假设我有一个HTML标记是这样的:如何使用jquery选择器来选择这样的元素?

<div> 
    <p> 
     this is the parent 
     <p> 
      this the child 
     </p> 
    </p> 
    <p> 
     this is the parent 
     <p> 
      this the child 
      <p>this is third child</p> 
     </p> 
    </p> 
</div> 

在div我有五个<p>标签,但我只想要使用jQuery选择器选择两个顶级父p标签,而不class和id名称

这是可能的吗?我该如何做到这一点?

回答

0

当然,只是做

$('div').children('p) 

孩子只能选择一个元素的直接孩子。不要忘了设置一个ID到你的分区...