|
| 1 | +var myNodelist = document.getElementsByTagName("LI"); |
| 2 | +var i; |
| 3 | +for (i = 0; i < myNodelist.length; i++) { |
| 4 | + var span = document.createElement("SPAN"); |
| 5 | + var txt = document.createTextNode("\u00D7"); |
| 6 | + span.className = "close"; |
| 7 | + span.appendChild(txt); |
| 8 | + myNodelist[i].appendChild(span); |
| 9 | +} |
| 10 | + |
| 11 | +var close = document.getElementsByClassName("close"); |
| 12 | +var i; |
| 13 | +for (i = 0; i < close.length; i++) { |
| 14 | + close[i].onclick = function() { |
| 15 | + var div = this.parentElement; |
| 16 | + div.style.display = "none"; |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +var list = document.querySelector('ul'); |
| 21 | +list.addEventListener('click', function(ev) { |
| 22 | + if (ev.target.tagName === 'LI') { |
| 23 | + ev.target.classList.toggle('checked'); |
| 24 | + } |
| 25 | +}, false); |
| 26 | + |
| 27 | +function newElement() { |
| 28 | + var li = document.createElement("li"); |
| 29 | + var inputValue = document.getElementById("myInput").value; |
| 30 | + var t = document.createTextNode(inputValue); |
| 31 | + li.appendChild(t); |
| 32 | + if (inputValue === '') { |
| 33 | + alert("You must write something!"); |
| 34 | + } else { |
| 35 | + document.getElementById("myUL").appendChild(li); |
| 36 | + } |
| 37 | + document.getElementById("myInput").value = ""; |
| 38 | + |
| 39 | + var span = document.createElement("SPAN"); |
| 40 | + var txt = document.createTextNode("\u00D7"); |
| 41 | + span.className = "close"; |
| 42 | + span.appendChild(txt); |
| 43 | + li.appendChild(span); |
| 44 | + |
| 45 | + for (i = 0; i < close.length; i++) { |
| 46 | + close[i].onclick = function() { |
| 47 | + var div = this.parentElement; |
| 48 | + div.style.display = "none"; |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments