This is a legit question: Code works well until the event listener is activated adding a new item to a list. Then All functionality is lost:
<!DOCTYPE html>
<html>
<head>
<title>Yo what up</title>
</head>
<body>
<div>
<input id='inpu' type="text">
<button type="button" id="click">Button</button>
</div>
<div>
<ol id="ol">
</ol>
</div>
<div>
<input id="addit" value="text">
<button id="butt">add item</button>
</div>
</body>
<script type="text/javascript">
let yo = document.getElementById("yo");
let inpu = document.getElementById("inpu");
let click = document.getElementById("click");
click.addEventListener("click", ()=> { yo.style.color=inpu.value});
let list = { "learn": {
"javascript": true,
"react": false,
"node": false,
"python": false,
"sql": false,
"Java": false
}}
let data = list["learn"];
let dataS = JSON.stringify(data);
let dataJ = JSON.parse(dataS);
console.log(dataJ);
let ol = document.getElementById("ol");
for (datu in dataJ){
console.log(dataJ[datu]);
let status = dataJ[datu]? "checked" : '';
let html = '<li class="box"><input + value=' + datu +' ' + 'type="checkbox"' + status + '>' + datu + '</li>';
ol.innerHTML += html;
}
let addit = document.getElementById("addit");
let butt = document.getElementById("butt")
butt.addEventListener("click", () => {
let nooo = addit.value
console.log(nooo);
dataJ[nooo] = false;
doIt(nooo);
})
function doIt(nooo){
let huml = '<li class="box"><input + value=' + nooo +' ' + 'type="checkbox"' + '>' + nooo + '</li>';
ol.innerHTML += huml;
}
onChange();
function onChange(){
let change = document.querySelectorAll('.box');
console.log(change);
for(index in change){
change[index].onchange = callIt;
}
}
function callIt(){
let key = event.target.value;
console.log(key);
dataJ[key] = event.target.checked;
}
</script>
</html>