-
Notifications
You must be signed in to change notification settings - Fork 335
/
Copy pathfunctions.js
29 lines (27 loc) · 1.09 KB
/
functions.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
const newsLetterButton = document.getElementById('newsletter-button');
const newsLetterSection = document.getElementById('newsletter-section');
const newsLetterEmail = document.getElementById('newsletter-email');
let sentEmail = false;
newsLetterButton.addEventListener('click', () => {
let newParagraph = document.createElement('p');
if (sentEmail) {
return;
}
const findAlert = document.getElementById('alert');
if (findAlert) {
findAlert.parentElement.removeChild(findAlert);
}
if (!newsLetterEmail.value) {
newParagraph.textContent = 'Veuillez saisir quelque chose !';
newParagraph.classList.add('alert-danger', 'w-100', 'p-2');
newParagraph.setAttribute('id', 'alert');
newsLetterSection.appendChild(newParagraph);
return;
}
newParagraph.textContent = 'Adresse email envoyée !';
newParagraph.classList.add('alert-success', 'w-100', 'p-2');
newsLetterSection.appendChild(newParagraph);
newsLetterSection.children[0].children[0].removeChild(newsLetterEmail);
newsLetterSection.children[0].children[0].removeChild(newsLetterButton);
sentEmail = true;
});