-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (42 loc) · 1.2 KB
/
index.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
let inputt = document.getElementById("inputt")
let msg = document.getElementById("msg")
let formm = document.getElementById("frm");
let posts = document.getElementById("posts");
formm.addEventListener("submit",(v)=>{
v.preventDefault();
formvalidation();
inputt.value = "";
})
function formvalidation(){
if(inputt.value === ""){
msg.innerHTML = "post can not be blank!";
}else if(inputt.value === " "){
msg.innerHTML = "It contains only white spaces";
}
else{
msg.innerHTML = "";
collect_data();
}
}
let data = {};
function collect_data(){
data["text"] = inputt.value;
console.log(data);
display_data();
}
function display_data(){
posts.innerHTML += `<div>
<p>${data.text}</p>
<span id="options">
<button id="ed" onClick="edit_post(this)">EDIT</button>
<button id="dl" onClick="delete_post(this)">DELETE</button>
</span>
</div>`;
}
function delete_post(e){
e.parentElement.parentElement.remove();
}
function edit_post(e){
inputt.value = e.parentElement.previousElementSibling.innerHTML;
e.parentElement.parentElement.remove();
}