试图让最后一个孩子进入CSS,但它不起作用

Fal*_*per 0 html css jquery

我很好奇为什么:

$("div.title").last();
Run Code Online (Sandbox Code Playgroud)

不会返回与css代码相同的项目:

$("div.title:nth-child(0)") 要么 $("div.title:last-child")

我试图在CSS中引用它,但似乎它似乎没有做到这一点.

html看起来像:

<div>
  <div class="title"></div>
  <div></div>
  <div class="title"></div>
  <div></div>
</div>
Run Code Online (Sandbox Code Playgroud)

Der*_*rek 6

:last-child 在CSS中只会选择元素,如果它是它的父元素的最后一个子元素,无论元素,类或任何其他选择器.

在jQuery中,.last()实际上将过滤您在jQuery选择器中获得的元素集合.