在特定元素后查找 Div

Find Div after specific element

我能够使用 .class textimage-text 获取元素内的所有 HTML。这很好用。然后我需要在下面的 Div 中获取 html,它没有 id 或 Class..

示例

<div class="textimage-text">
  <p>Some Text goes here</p>
</div>
<br>
<div>
  <p>Some additional Text goes here</p>
</div>

$.get(item.url, function (html) {

  var body = $(html).find(".textimage-text").html(); // <- this works
  var more= $(html).find(".textimage-text").next("div").html(); // <- this does not work

在 next 函数中添加一个额外的 .next() 并删除 "div" 参数,目前你是选择 br

var more= $(html).find(".textimage-text").next().next().html()

使用通用同级选择器 ~(例如:~ div 查找下一个 div 是它的同级)

$(html).find(".textimage-text ~ div").html();

$('.textimage-text ~ div').html()

General sibling selectors

The general sibling combinator (~) separates two selectors and matches the second element only if it follows the first element (though not necessarily immediately), and both are children of the same parent element.

示例:

console.log($('body').find('.textimage-text').html());
console.log($('body').find('.textimage-text ~ div').html());

console.log($('.textimage-text').html());
console.log($('.textimage-text ~ div').html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="textimage-text">
  <p>Some Text goes here</p>
</div>
<br>
<div>
  <p>Some additional Text goes here</p>
</div>