-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdom-amplify.js
More file actions
46 lines (38 loc) · 1023 Bytes
/
dom-amplify.js
File metadata and controls
46 lines (38 loc) · 1023 Bytes
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
;(function() {
// Query sellectors
var qs = function(css) {
return document.querySelector(css);
};
var qsa = function(css) {
return document.querySelectorAll(css);
};
// Create elements
var el = function(type, props, children) {
return document.createElement(type, props, children);
};
var txt = function(string) {
return document.createTextNode(string);
};
// Find text on a page (returns true or false) *
var find = function(string) {
var result = document.documentElement.innerHTML.indexOf(string);
result = (result != -1) ? true : false;
return result;
};
// Class Replacement
Element.prototype.replaceClass = function(oldClass, newClass) {
this.classList.remove(oldClass);
this.classList.add(newClass);
};
// Function check if the element included on a page body *
Element.prototype.isInPage = function() {
return (this === document.body) ? false : document.body.contains(this);
};
window.dom = {
qs: qs,
qsa: qsa,
el: el,
txt: txt,
find: find
};
})();