forked from ThatsNoMoon/thinquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
45 lines (33 loc) · 1.19 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
export class ThinQuery {
doc: Document;
constructor(doc: Document) {
this.doc = doc;
}
id = (id: string) => this.doc.getElementById(id);
class = (name: string) => Array.from(this.doc.getElementsByClassName(name));
select = (selector: string) => this.doc.querySelector(selector);
selectAll = (selector: string) => {
return Array.from(this.doc.querySelectorAll(selector));
};
addClass = (name: string) => (element: Element) => {
element.classList.add(name);
};
removeClass = (name: string) => (element: Element) => {
element.classList.remove(name);
};
addCss = (css: Partial<CSSStyleDeclaration>) => {
return (element: ElementCSSInlineStyle) => {
Object.assign(element.style, css);
};
};
setAttribute = (name: string, value: string) => (element: Element) => {
element.setAttribute(name, value);
};
getAttribute = (name: string) => (element: Element) => {
return element.getAttribute(name);
};
setValue = (value: string) => (element: HTMLInputElement) => {
element.value = value;
};
getValue = (element: HTMLInputElement) => element.value;
}