-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
47 lines (38 loc) · 1.99 KB
/
script.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
//Create global variables
let meme = document.querySelector('#meme-image');
let outerMemeContainer = document.querySelector('#meme-container')
//MAIN FUNCTION
function submitForm() {
//Creace variables needed to get input values
let topText = document.querySelector('#top-text-input').value;
let bottomText = document.querySelector('#bottom-text-input').value;
let image = document.querySelector('#url-image').value;
//Create div for meme
let innerMemeContainer = document.createElement('div');
outerMemeContainer.appendChild(innerMemeContainer); // Add div inside meme div
innerMemeContainer.classList.add('inner-div'); //Add class
//Append image to div
let newImg = document.createElement("img"); //Create img element
newImg.src = image; //Add src to img alement
newImg.classList.add('loaded-image') //Add class
innerMemeContainer.appendChild(newImg); //Add img to div
//Insert top text
let topTextDiv = document.createElement('div'); //Create div for top text
innerMemeContainer.appendChild(topTextDiv); //Add div to meme
topTextDiv.classList.add('top-text'); //Add class
topTextDiv.innerText = topText; //Add text
//Insert bottom txxt
let bottomTextDiv = document.createElement('div');
innerMemeContainer.appendChild(bottomTextDiv);
bottomTextDiv.classList.add('bottom-text');
bottomTextDiv.innerText = bottomText;
//Create delete button
let deleteBtn = document.createElement('button'); //Create delete button
innerMemeContainer.appendChild(deleteBtn); //Add button to meme div
deleteBtn.innerText = 'Delete'; // Add text to button
deleteBtn.classList.add('delete-button'); //Add class
//Create event listener to delete single meme when clicked on
deleteBtn.addEventListener ( 'click', function () { //Create event listener with function
innerMemeContainer.parentNode.removeChild(innerMemeContainer); //Remove single div that contains a meme
});
}