<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> </style></head><body> <input type="text" id="inp"> <div class="box"></div> <script> var inp = document.querySelector('#inp') var box = document.querySelector(".box") var arr = [] inp.addEventListener('keyup', function (e) { if (e.keyCode == 13) { var value = this.value if (!arr.includes(value)) { arr.push(value) var p = document.createElement('p') var txt = document.createTextNode(value); p.appendChild(txt) box.appendChild(p) for (let i = 0; i < box.children.length; i++) { box.children[i].onclick = function () { // console.log(this); box.removeChild(this); } } } // .appendChild(p) } }) </script></body></html>