@mdui/jq
Version:
拥有和 jQuery 相似 API 的轻量级 JavaScript 工具库
14 lines (13 loc) • 583 B
JavaScript
import { $ } from '../$.js';
import { eachArray } from '../shared/helper.js';
import './get.js';
import { dir } from './utils/dir.js';
eachArray(['', 'All', 'Until'], (name, nameIndex) => {
$.fn[`prev${name}`] = function (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
selector, filter) {
// prevAll、prevUntil 需要把元素的顺序倒序处理,以便和 jQuery 的结果一致
const $nodes = !nameIndex ? this : $(this.get().reverse());
return dir($nodes, nameIndex, 'previousElementSibling', selector, filter);
};
});