Прочитайте мой комментарий. Вот что, я думаю, вы действительно хотите сделать:
//<![CDATA[
/* js/external.js */
let get, post, doc, html, bod, nav, M, I, mobile, S, Q, aC, rC, tC; // for use on other loads
addEventListener('load', ()=>{
get = (url, success, context)=>{
const x = new XMLHttpRequest;
const c = context || x;
x.open('GET', url);
x.onload = ()=>{
if(success)success.call(c, JSON.parse(x.responseText));
}
x.send();
}
post = function(url, send, success, context){
const x = new XMLHttpRequest;
const c = context || x;
x.open('POST', url);
x.onload = ()=>{
if(success)success.call(c, JSON.parse(x.responseText));
}
if(typeof send === 'object' && send && !(send instanceof Array)){
if(send instanceof FormData){
x.send(send);
}
else{
const fd = new FormData;
for(let k in send){
fd.append(k, JSON.stringify(send[k]));
}
x.send(fd);
}
}
else{
throw new Error('send argument must be an Object');
}
return x;
}
doc = document; html = doc.documentElement; bod = doc.body; nav = navigator; M = tag=>doc.createElement(tag); I = id=>doc.getElementById(id);
mobile = nav.userAgent.match(/Mobi/i) ? true : false;
S = (selector, within)=>{
var w = within || doc;
return w.querySelector(selector);
}
Q = (selector, within)=>{
var w = within || doc;
return w.querySelectorAll(selector);
}
aC = function(){
const a = [].slice.call(arguments), n = a.shift();
n.classList.add(...a);
return aC;
}
rC = function(){
const a = [].slice.call(arguments), n = a.shift();
n.classList.remove(...a);
return rC;
}
tC = function(){
const a = [].slice.call(arguments), n = a.shift();
n.classList.toggle(...a);
return tC;
}
// you can put all the below on a separate page in a load Event - besides the end load
const text_in = I('text_in'), list_add = I('list_add'), list = I('list');
function addText(){
let v = text_in.value.trim();
if(v !== ''){
const li = M('li'), div = M('div'), remove = M('input');
div.textContent = v; remove.type = 'button'; remove.value = 'remove'; aC(remove, 'remove');
remove.onclick = ()=>{
list.removeChild(li); text_in.focus();
}
li.appendChild(div); li.appendChild(remove); list.appendChild(li);
}
text_in.value = ''; text_in.focus();
}
list_add.onclick = addText;
text_in.onkeyup = e=>{
if(e.key === 'Enter')addText();
}
}); // end load
//]]>
/* css/external.css */
*{
padding:0; margin:0; font-size:0; border:0; box-sizing:border-box; outline:none; overflow:hidden; -webkit-tap-highlight-color:transparent;
}
html,body{
width:100%; height:100%; background:#ccc;
}
.main{
padding:10px;
}
input,#list_adder>ul>li{
font:bold 22px Tahoma, Geneva, sans-serif;
}
input[type=text]{
width:calc(100% - 75px); padding:3px 5px; border-radius:3px;
}
input[type=button]{
cursor:pointer; width:75px; background:linear-gradient(#1b7bbb,#147); color:#fff; padding:3px 0; border-radius:5px;
}
input[type=button].remove{
position:absolute; right:5px; top:5px; background:linear-gradient(#b75757,#502323); font-size:14px;
}
#list_adder>ul{
list-style:none;
}
#list_adder>ul>li{
position:relative; background:#eee; padding:3px 5px; border:1px solid #000; margin-top:7px; border-radius:2px;
}
#list_adder>ul>li>div{
display:inline-block; font-size:14px;
}
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<meta charset='UTF-8' /><meta name='viewport' content='width=device-width, height=device-height, initial-scale:1, user-scalable=no' />
<title>Title Here</title>
<link type='text/css' rel='stylesheet' href='css/external.css' />
<script src='js/external.js'></script>
</head>
<body>
<div class='main'>
<section id='list_adder'>
<input id='text_in' type='text' placeholder='Add Something Here' /><input id='list_add' type='button' value='ADD' />
<ul id='list'></ul>
</section>
</div>
</body>
</html>