-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
41 lines (33 loc) · 1.14 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
// Enhanced JavaScript to dynamically add a menu item with additional functionality
document.addEventListener('DOMContentLoaded', () => {
const menuList = document.querySelector('.menu-list');
// Function to create a new menu item
const createMenuItem = () => {
const newMenuItem = document.createElement('li');
newMenuItem.className = 'menu-item';
newMenuItem.innerHTML = `
<h2>Beverages</h2>
<p>Tea, Coffee, Juice</p>
<button class="remove-btn">Remove</button>
`;
// Add animation class
newMenuItem.classList.add('fade-in');
// Add event listener to the remove button
newMenuItem.querySelector('.remove-btn').addEventListener('click', () => {
menuList.removeChild(newMenuItem);
});
menuList.appendChild(newMenuItem);
};
// Call the function to create and add the menu item
createMenuItem();
});
// CSS for fade-in animation (add this to your CSS file)
/*
.fade-in {
opacity: 0;
transition: opacity 0.5s ease-in;
}
.menu-item {
opacity: 1;
}
*/