-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice_ex2.js
More file actions
26 lines (23 loc) · 794 Bytes
/
Copy pathpractice_ex2.js
File metadata and controls
26 lines (23 loc) · 794 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
26
/*
You have to create a div and inject it into the page which contains a heading.
whenever someone clicks on the div, it should be converted into an editable item. whenever user clicks away (blur). save the note into the local storage.
*/
console.log("we are in practice session!");
localStorage.clear();
let element = document.querySelector('h1');
element.addEventListener('click',fun);
let element2 = document.createElement('div');
let text = document.createElement('textarea');
element2.className = 'disp2';
element2.addEventListener('click',fun2);
text.addEventListener('blur',fun4)
function fun(e){
element.replaceWith(element2);
}
function fun2(e){
element2.replaceWith(text);
}
function fun4(e){
let textval = text.value;
localStorage.setItem('valuebyuser',textval);
}