-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (27 loc) · 1.24 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
// script.js
document.addEventListener('DOMContentLoaded', () => {
const characters = document.querySelectorAll('.character');
const confirmBtn = document.getElementById('confirm-btn');
const selectedCharacterParagraph = document.getElementById('selected-character');
let selectedCharacter = null;
characters.forEach(character => {
character.addEventListener('click', () => {
// Remove 'selected' class from all characters
characters.forEach(char => char.classList.remove('selected'));
// Add 'selected' class to the clicked character
character.classList.add('selected');
// Store selected character
selectedCharacter = character.getAttribute('data-name');
// Update the paragraph to show the selected character
selectedCharacterParagraph.textContent = `${selectedCharacter}`;
});
});
confirmBtn.addEventListener('click', () => {
if (selectedCharacter) {
alert(`You have selected: ${selectedCharacter}`);
window.location.href = 'PaginaIniziale.html';
} else {
alert('No character selected');
}
});
});