-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookies.js
More file actions
42 lines (32 loc) · 1.49 KB
/
cookies.js
File metadata and controls
42 lines (32 loc) · 1.49 KB
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
window.addEventListener('load', init);
function init() {
// Cookie Bar Element
const cookieBar = document.createElement("div");
cookieBar.setAttribute("id", "cookie-bar");
// Cookie Text Element
const cookieText = document.createElement("div");
cookieText.setAttribute("id", "cookie-text");
const cookieTextNode = document.createTextNode("By using this site you agree to our cookie policy");
// Cookie Controller Element
const cookieController = document.createElement("div");
cookieController.setAttribute("id", "cookie-controller");
// Cookie Controller Span
const cookieControllerSpan = document.createElement("span");
cookieControllerSpan.setAttribute("id", "cookie-controller-span");
const cookieControllerSpanNode = document.createTextNode("[X]");
// Onclick Event
cookieControllerSpan.onclick = function() {
document.getElementById("cookie-bar").style.display = 'none';
};
// Append text as a child of Cookie Text
cookieText.appendChild(cookieTextNode);
// Append Cookie Controller Span Node as a child of Controller Span
cookieControllerSpan.appendChild(cookieControllerSpanNode);
// Append span as a child of Cookie Controller
cookieController.appendChild(cookieControllerSpan);
// Append all elements as a children of Cookie Bar
cookieBar.appendChild(cookieText);
cookieBar.appendChild(cookieController);
// Append Cookie Bar as a child of Body
document.body.appendChild(cookieBar);
}