使用 JQuery 选择页面上第一个元素中第一个出现的子项?

Selecting the First Appearing Child Within the First Element On a Page with JQuery?

我想在 .load() 方法中使用 gt() 选择器。这能实现吗?

目前,我正在寻找一种解决方案,允许我在调用 .entry:first 之后应用 .children(':gt(0)') 选择器。

这是我到目前为止的进度:

$("#embed-content").load("https://URL.com/page/ .entry:first .children(':gt(0)')", function(data) {});

请注意,加载源的第一个元素并不总是 div,也不总是包含相同的 ID 或 class,这些方面会有所不同。

.entry:first .children(':gt(0)') 将是 .entry:first > :gt(0)> 是直接子组合子,然后 :gt(0) 当然是 "greater than index 0".

不过我认为这不是您想要的。在评论中你说:

I am trying to select the first child element within the first .entry div from the loaded page source.

:gt(0) 跳过 第一个这样的元素,而不是 selecting 它。 select 你想要的:.entry:first > :first:

$(".entry:first > :first").css({
  color: "green",
  fontWeight: "bold"
});
<div class="entry">
  <span>first child of first .entry</span>
  <span>second child of first .entry</span>
</div>
<div class="entry">
  <span>first child of second .entry</span>
  <span>second child of second .entry</span>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>