-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathscript.js
49 lines (38 loc) · 1.59 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
42
43
44
45
46
47
48
49
const container = document.querySelector('.container') // set .container to a variable so we don't need to find it every time we click
let noteCount = 1 // inital value
const messageBox = document.querySelector('#messageBox')
// access our button and assign a click handler
document.querySelector('.box-creator-button').addEventListener('click', () => {
// create our DOM element
const stickyNote = document.createElement('div')
// set our class name
stickyNote.className = 'box'
// get our other DOM elements
const stickyMessage = document.querySelector('.box-color-note')
const stickyColor = document.querySelector('.box-color-input')
// get our variables
const message = stickyMessage.value
const color = stickyColor.style.backgroundColor
// blank out the input fields
stickyMessage.value = stickyColor.value = ''
stickyColor.style.backgroundColor = '#fff'
// define the attributes
stickyNote.innerHTML = `${noteCount++}. ${message}`
stickyNote.style.backgroundColor = color
// add the sticky
container.appendChild(stickyNote)
})
document.querySelector('#close').addEventListener('click', (e) => {
messageBox.style.visibility = 'hidden'
})
container.addEventListener('click', (e) => {
if (e.target.className === 'box') {
document.querySelector('#color').innerHTML = e.target.style.backgroundColor
document.querySelector('#message').innerHTML = e.target.innerHTML
messageBox.style.visibility = 'visible'
document.querySelector('#delete').addEventListener('click', (event) => {
messageBox.style.visibility = 'hidden'
e.target.remove()
})
}
})