Не удаляется элемент при нажатии кнопки удалить. Вот сам код:
<html lang="ru">
<head>
<title>Resourse menager | by yuroo.com</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css" media="screen">
</head>
<body>
<main>
<script src="main.js"></script>
<input id="list" type="button" value="Add Line!">
<input type="text" id="line" placeholder="Write a some line here!"> <br>
<input id="rem" type="button" value="Remove a some line!">
<input type="text" placeholder="Write id from list!" id="linedel">
<style>
ul {
list-style: square;
}
li {
background: lightgray;
display: block;
height: 40px;
border-radius: 5px;
text-align: left;
font-size: 20px;
padding-left: 20px;
padding-top: 10px;
}
li:hover {
background: gray;
transition: 0.3s;
}
</style>
<script>
list.onclick = function () {
let create = document.createElement('ul')
document.body.append(create)
let data = document.getElementById("line").value
if(!data){
alert("Please. Write a line!")
} else {
let li = document.createElement('li')
li.textContent = data
li.id = ID()
li.textContent = " " + ID()
document.body.append(li)
}
}
let ID = function () {
return '_' + Math.random().toString(36).substr(2, 9);
}
rem.onclick = function () {
let linedel = document.getElementById("linedel").value
let li = document.querySelector(linedel)
// let li = document.getElementById(linedel)
if(!linedel){
alert("Please. Write a line!")
} else {
li.remove() //Здесь ошибка -----------------------------------------------------------------------
}
}
</script>
</main>
</body>
</html>