-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddItem.js
More file actions
25 lines (21 loc) · 800 Bytes
/
addItem.js
File metadata and controls
25 lines (21 loc) · 800 Bytes
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
function addItem(name, image, content) {
const div = document.createElement("div");
div.classList.add("card");
div.innerHTML = `
<img src="${image}" alt="${name}" />
<span>${content}</span>
`;
document.querySelector("#container").appendChild(div);
const span = document.createElement("span");
span.innerHTML = name;
document.querySelector("#sidebar").appendChild(span);
}
function addItemHandle(e){
e.preventDefault();
const name = document.getElementById("name").value;
const image = document.getElementById("image").value;
const content = document.getElementById("content").value;
addItem(name, image, content);
closeModal();
}
document.getElementById("addItemForm").addEventListener("submit", addItemHandle);