-
Notifications
You must be signed in to change notification settings - Fork 0
/
elementailor.js
73 lines (58 loc) · 2.14 KB
/
elementailor.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* _____ _ _____ _ _ _
* | ____| | ___ _ __ ___ ___ _ _|_ _|_ _(_) | ___ _ __ (_)___
* | _| | |/ _ \ '_ ` _ \ / _ \ '_ \| |/ _` | | |/ _ \| '__|| / __|
* | |___| | __/ | | | | | __/ | | | | (_| | | | (_) | | _ | \__ \
* |_____|_|\___|_| |_| |_|\___|_| |_|_|\__,_|_|_|\___/|_|(_)/ |___/
* |__/
*
* @description Javascript Library for creating elements & doms with ease.
* @author Sebastian Robert Karlsson | sebbekarlsson97@gmail.com
*
* This is just a very lightweight object that you can use for creating
* elements & doms.
*
* Use the ElemenTailor.create() function to create elements.
* You can add classes, identifier and childs in one call.
*
* Use the ElemenTailor.delete() function to delete elements.
*
* Have fun!
*/
var ElemenTailor = {
/**
* This function is used to create an element.
* @param e_name - name of element (example: 'div')
* @param attributes - attributes for element (example: {class: 'btn'})
* @return HTMLElement - returns an HTML element.
*/
create: function(
e_name,
attributes
) {
var element = document.createElement(e_name);
if (attributes == undefined) attributes = {};
for (key in attributes) {
if (key in element)
element[key] = attributes[key];
element.setAttribute(key, attributes[key])
}
if ('childs' in attributes)
for (var i = 0; i < attributes['childs'].length; i++)
element.appendChild(attributes['childs'][i]);
return element;
},
/**
* This function is used to delete an element.
* @param element - The element to delete.
* @return element - the element that was removed
*/
delete: function(element) {
if (element == undefined) return false;
var parent = element.parentNode;
if (parent == undefined) return false;
return parent.removeChild(element);
}
};
if (typeof module !== 'undefined' && module.exports)
module.exports = ElemenTailor;