-
Notifications
You must be signed in to change notification settings - Fork 0
/
jQuery-x.js
42 lines (34 loc) · 920 Bytes
/
jQuery-x.js
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
function jQueryX(selector) {
if(!(this instanceof jQueryX)) {
return new jQueryX(selector)
}
this.push.apply(this, document.querySelectorAll(selector))
}
jQueryX.prototype = []
jQueryX.prototype.each = function(callback) {
this.forEach(callback)
return this
}
jQueryX.fn = jQueryX.prototype
const $ = ( window.$ = jQueryX )
/*--------------------------SAMPLE FUNCTIONS---------------------------*/
jQueryX.fn.addClass = function(className) {
return this.each(element => {
element.classList.add(className)
})
}
jQueryX.fn.color = function(color) {
return this.each(element => {
element.style.color = color
})
}
jQueryX.fn.attr = function(attr, value) {
return this.each(element => {
element.setAttribute(attr, value)
})
}
jQueryX.fn.innerHTML = function(text) {
return this.each(element => {
element.innerHTML = text
})
}