jquery选择标题后的任何第一个p元素是否还有其他元素

jquery选择标题后的任何第一个p元素是否还有其他元素,jquery,html,jquery-selectors,Jquery,Html,Jquery Selectors,我试图改变h2或h3元素之后的第一个p元素,不管中间是否有其他元素 所以这个的html是 <h3>This is the subhead in use</h3> <img src="http://placehold.it/350x150"/> <p>Here is some lipsum orum kind of textHere is some lipsum orum kind of textHere is some lipsum orum ki

我试图改变h2或h3元素之后的第一个p元素,不管中间是否有其他元素

所以这个的html是

<h3>This is the subhead in use</h3>
<img src="http://placehold.it/350x150"/>
<p>Here is some lipsum orum kind of textHere is some lipsum orum kind of textHere is some lipsum orum kind of textHere is some lipsum orum kind of textHere is some lipsum orum kind of text</p>
<p>Here is some lipsum orum kind of textHere is some lipsum orum kind of textHere is some lipsum orum kind of textHere is some lipsum orum kind of textHere is some lipsum orum kind of text</p>
<h3>This is the subhead in use</h3>
<p>Here is some lipsum orum kind of text</p>

<aside>
  <h2>This is the aside title</h2>
  <p>Here is some more lipsum orem. Here is some more lipsum orem. Here is some more lipsum orem. Here is some more lipsum orem.</p>
</aside>
因此,它会在h3或h3标记后找到第一个p,但如果中间有另一个元素,则不会找到它。不总是这样,但有时我希望img、div或figure元素位于h2或h3之后,但仍然希望jquery找到第一个p(在上面的代码中,它失败了)

我已经尝试了许多选择器和方法的组合,包括p:first of type、兄弟姐妹、nextAll等。我希望在不向html部分的第一个p元素添加类的情况下完成这项工作


请帮助。

它没有按预期工作,因为它将只选择紧跟其后的
p
元素。您可以使用选择以下所有
p
元素(不仅仅是紧跟其后的元素),然后链接
.first()
方法以获得集合中的第一个匹配项:


它没有按预期工作,因为将只选择紧跟其后的
p
元素。您可以使用选择以下所有
p
元素(不仅仅是紧跟其后的元素),然后链接
.first()
方法以获得集合中的第一个匹配项:


我认为HTML是无效的。我认为HTML是无效的。
$(function(){
  $('h3, h2').next('p').css({ "color":"green"});    
});
$('h3, h2').each(function () {
  $(this).nextAll('p').first().css({ "color":"green"});
});