"splice"
Bootstrap 4.0.0 Snippet by lavan

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!DOCTYPE html> <html> <body> <input type="text" id="input"> <button onclick="add()">ADD</button> <ul id="save"> <li> </li> </ul> <script> var db=[] function clr(id){ if (id.style.background=='blue' ){ id.style.background='' } else { id.style.background='blue' } } function deleteli(i){ db.splice(i,2); var lavan="" for (var i=0;i<db.length;i++){ lavan +="<li onclick='clr(this)'>"+db[i]+"<button onclick='deleteli("+i+")'>delete</button></li> "; } document.getElementById('save').innerHTML=lavan } function add(){ var store=document.getElementById('input').value document.getElementById('input').value="" document.getElementById('input').focus() db.push(store) var lavan="" alert(db.length) for (var i=0;i<db.length;i++){ lavan +="<li onclick='clr(this)'>"+db[i]+"<button onclick='deleteli("+i+")'>delete</button></li> "; } document.getElementById('save').innerHTML=lavan } </script> </body> </html>

Related: See More


Questions / Comments: