今天写$("ul li:last-child").offset().top发现报错,而$("ul li").last().offset().top就没错了。原因在于:
这两个选择器都是匹配集合中的最后一个元素,差别在于 :last 将匹配所有的集合中的最后一个元素。而 :last-child 将匹配集合中的所有位置为最后一个的子元素。:last 将永远返回一个元素,而 :last-child可能返回一批元素。
原来如此啊!
:last Selects the last matched element.
Note that :last selects a single element by filtering the current jQuery collection and matching the last element within it.
Additional Notes:
Because :last is a jQuery extension and not part of the CSS specification, queries using
:last cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method.
To achieve the best performance when using :last to select elements, first select the elements using a pure CSS selector, then use.filter(":last").:last-child:
Selects all elements that are the last child of their parent.
John, Karl, Brandon, SamGlen, Tane, Ralph, David









