<head> <metacharset="UTF-8"> <metahttp-equiv="X-UA-Compatible"content="IE=edge"> <metaname="viewport"content="width=device-width, initial-scale=1.0"> <title>Document</title> <scriptsrc="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(function() { let n = 6, i = 1; let text = ""; for (i; i < n; i++) { text += "<li>" + i + "</li>"; } $("ul").append(text); $("#addItem").click(function() { let newItem = ""; newItem = "<li>" + i + "</li>"; i += 1; $("ul").append(newItem); }); $("#deleteItem").click(function() { let tmp = $("ul").html().toString(); let location = tmp.lastIndexOf('<li>'); $('ul').html(tmp.slice(0, location)); i -= 1; }); $("#traversal").click(function() { let res = []; for (j = 0; j < $("li").length; j++) { res.push($("li").eq(j).text()) } $("#res").text(res); }); $("#modifyItem").click(function() { let index = $("#index").val(); let value = $("#value").val(); $("li").eq(index - 1).text(value); }) }) </script> </head>