40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
const button = document.getElementById("addbtn")
|
|
const notes = document.getElementById("notes")
|
|
const msg = document.getElementById("msg")
|
|
let idnum = 1
|
|
|
|
|
|
button.addEventListener("click", ()=>{
|
|
let inphead = document.getElementById("inphead")
|
|
let inptext = document.getElementById("inptext")
|
|
console.log(inphead.value);
|
|
if (inphead.value != "" && inptext.value != ""){
|
|
let newnote = document.createElement("div")
|
|
newnote.innerHTML = `<h3>${inphead.value}</h3>`
|
|
newnote.innerHTML += `<p>${inptext.value}<p>`
|
|
newnote.classList.add("notescss")
|
|
newnote.setAttribute("id", `note-${idnum++}`)
|
|
newnote.setAttribute("title", "Kattintásra törölheted a jegyzetedet...")
|
|
newnote.style.background = document.getElementById("notecolor").value
|
|
notes.appendChild(newnote)
|
|
msg.innerHTML = ""
|
|
msg.innerHTML = "<i>Üzenet hozzáadva!</i>"
|
|
inphead.value = ""
|
|
inptext.value = ""
|
|
|
|
newnote.onclick = function(){
|
|
this.parentElement.removeChild(this)
|
|
|
|
}
|
|
|
|
notes.appendChild(newnote)
|
|
|
|
msg.innerHTML = '<span class="msgok">Üzenet hozzáadva!</span'
|
|
inphead.value = ""
|
|
inptext.value = ""
|
|
|
|
} else{
|
|
msg.innerHTML = '<span class="msgerr">Töltsd ki a hiányzó mezőket!</span'
|
|
}
|
|
|
|
}) |