-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
100 lines (74 loc) · 3.55 KB
/
index.html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="styles.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans+Condensed:wght@300&display=swap" rel="stylesheet">
<title></title>
<script type="text/javascript">
window.onload= function (){
var id= 0;
const form = document.getElementById('memeForm');
form.addEventListener('submit', event => {
if(document.getElementById("img").value.length > 0){
id++;
const newDiv = document.createElement("div");
newDiv.className = "container";
var img = new Image();
img.src = document.getElementById("img").value ;
img.setAttribute('id', 'img'+id);
img.setAttribute('alt', 'INVALID IMAGE');
newDiv.appendChild(img);
const topTextDiv = document.createElement("div");
topTextDiv.className="top-left";
var topTxt = document.createTextNode(document.getElementById("topTxt").value );
topTextDiv.appendChild(topTxt)
newDiv.appendChild(topTextDiv);
var a = document.createElement('a');
a.setAttribute('href', '#');
var img = new Image();
img.src = "icons/delete-64.png" ;
img.setAttribute("style","width:40px;height:40px;" );
img.className ='delete';
img.setAttribute('id', 'del'+id);
a.appendChild(img);
a.onclick = function(e){
e.preventDefault();
var element = document.getElementById(e.target.id);
element.parentNode.parentElement.remove();
}
newDiv.appendChild(a);
const bottomTextDiv = document.createElement("div");
bottomTextDiv.className="bottom-left";
var bottomTxt = document.createTextNode(document.getElementById("bottomTxt").value );
bottomTextDiv.appendChild(bottomTxt)
newDiv.appendChild(bottomTextDiv);
document.getElementById('pageDiv').appendChild(newDiv);
form.reset();
}
else {
alert("Please add an image link.");
}
event.preventDefault();
});
}
</script>
</head>
<body>
<h1> MEME Generator</h1>
<div class="form">
<h4> Add your favourite memes !!</h4>
<form name="memeForm" id="memeForm">
<label class="label">Enter the image URL</label>
<input type="text" id="img" name="img" class="text"></textarea><br><br>
<label class="label">Text on top</label>
<input type="text" id="topTxt" name="topTxt" class="text" MaxLength="70"><br/><br>
<label class="label">Text on bottom:</label>
<input type="text" id="bottomTxt" name="bottomTxt" class="text" MaxLength="70"><br/><br>
<input type="submit" value="Add Meme" class="btn" />
</form>
</div>
<div id="pageDiv" class="pageDiv">
</div>
</body>
</html>