-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (47 loc) · 1.24 KB
/
index.js
File metadata and controls
49 lines (47 loc) · 1.24 KB
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
48
49
window.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('form1');
const body = document.getElementById('body');
function renderCard(name, position, teamName) {
return `
<div class="card">
<img src="https://placekitten.com/500/600" class="kitty">
<div class="bottom">
<div class="bottomleft">
<div class="name">
${name}
</div>
<div class="position">
${position}
</div>
: </div>
<div class="bottomright">
<div class="team">
${teamName}
</div>
</div>
</div>
</div>
`;
}
function cardSubmit(event) {
body.insertAdjacentHTML(
"beforeend",
renderCard(
form.name.value,
form.position.value,
form.team.value
)
)
const cardObject = {
name: form.name.value,
position: form.position.value,
teamName: form.team.value
}
localStorage.setItem(
localStorage.length,
JSON.stringify(cardObject)
)
event.preventDefault();
};
form.addEventListener('submit', cardSubmit);
});