getAllEle

说明

获取指定的所有DOM元素

源码

用法

getAllEle.test.ts
1
import { getAllEle } from "../../utility/dom/getAllEle";
2
import { getEle } from "../../utility/dom/getEle";
3
4
describe('getAllEle', () => {
5
test('getEle should return `null` when no matched', () => {
6
document.body.innerHTML = `
7
<div id="app">
8
<p class="text"></p>
9
<p class="text"></p>
10
<p class="text"></p>
11
</div>
12
`;
13
14
const origin = [
15
'span', '.link',
16
];
17
18
for (const v of origin) {
19
expect(getEle(v)).toBe(null);
20
}
21
});
22
23
test('getEle should return all of the `DOM object` which have been matched', () => {
24
document.body.innerHTML = `
25
<div id="#app">
26
<p class="text"></p>
27
<p class="text"></p>
28
<p class="text"></p>
29
</div>
30
`;
31
32
const origin = ['.text'];
33
34
for (const v of origin) {
35
expect(getAllEle(v)).toBe(
36
document.querySelectorAll('.text')
37
);
38
}
39
});
40
});
Copied!
最近更新 1yr ago
复制链接