JSFiddle - React, Tailwind, and code Playground
by Spring
HTML
<!DOCTYPE html>
<html>
<head>
<title>Javascript todo list.</title>
<body>
<div id = "site-wrap">
<h3>Click on the specfic element in the todo list you wish to delete.</h3>
<textarea placeholder="Describe yourself with 4 words..." id ="txt">
</textarea><br />
<input type = "submit" value ="Add" id ="submit"/>
<ul id = "todo">
<li>
Todo..
</li>
<li>
Todo..
</li>
</ul>
<div style="clear:both;"></div>
</div>
</body>
</head>
</html>
CSS
#site-wrap{
width:400px;
height:150px;
margin:0 auto;
padding:10px;
}
ul{
margin-bottom:50px;
float:right;
margin:0 50px 30px 0;
}
textarea{
float:left;
}
JavaScript
var todoList = {
list: document.getElementById("todo"),
remove: function(obj) {
//Completely remove node from the DOM.
obj.parentNode.removeChild(obj);
},
add: function(str) {
if (str !== '' || str !== undefined) {
//Create an new element.
var li = document.createElement("li");
li.innerHTML = str;
this.list.appendChild(li);
}
}
};
//Get the UL and delete the selected target.
todoList.list.onclick = function() {
todoList.remove(event.target);
};
//On submit get the value of the textarea
document.getElementById("submit").onclick = function() {
todoList.add(this.parentNode.childNodes[3].value);
};