equation-admin-template
Version:
Booststrap 4 admin template made by equation
66 lines (59 loc) • 2.02 kB
JavaScript
$('.addBtn').on('click', function(event) {
event.preventDefault();
/* Act on the event */
newElement();
});
// Create a "close" button and append it to each list item
var myNodelist = document.getElementsByClassName("todo-item");
var i;
for (i = 0; i < myNodelist.length; i++) {
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00D7");
span.className = "close";
span.appendChild(txt);
myNodelist[i].appendChild(span);
}
// Click on a close button to hide the current list item
var close = document.getElementsByClassName("close");
var i;
for (i = 0; i < close.length; i++) {
close[i].onclick = function() {
var div = this.parentElement;
div.style.display = "none";
}
}
// Add a "checked" symbol when clicking on a list item
var list = document.getElementById('todo-items-container');
list.addEventListener('click', function(ev) {
if (ev.target.tagName === 'LI') {
ev.target.classList.toggle('checked');
}
}, false);
// Create a new list item when clicking on the "Add" button
function newElement() {
var li = document.createElement("li");
console.log(li);
li.className += "todo-item";
var inputValue = document.getElementById("myInput").value;
console.log(inputValue);
var t = document.createTextNode(inputValue);
console.log(t);
li.appendChild(t);
if (inputValue === '') {
alert("You must write something!");
} else {
document.getElementById("todo-items-container").appendChild(li);
}
document.getElementById("myInput").value = "";
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00D7");
span.className = "close";
span.appendChild(txt);
li.appendChild(span);
for (i = 0; i < close.length; i++) {
close[i].onclick = function() {
var div = this.parentElement;
div.style.display = "none";
}
}
}