JSFiddle - React, Tailwind, and code Playground
HTML
<div class="content">
<span class="" >Please, insert one or more emails: </span> <br />
<ul id="ulEmailsCotacao" class="ulEmailsCotacao">
<li class="liEmailTagNew">
<input type="text" class="emailInputTag" name="" value="" />
</li>
</ul>
</div>
CSS
ul
{
display: block;
list-style-type: disc;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 40px;
}
input
{
margin: 0em;
font: -webkit-small-control;
color: initial;
letter-spacing: normal;
word-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
display: inline-block;
text-align: start;
}
.ulEmailsCotacao
{
cursor: text;
overflow: auto;
font-size: 14px;
width: 97%;
padding: 3px;
margin-top: 2px;
margin-right: 6px;
margin-bottom: 16px;
border: 1px solid #E5E5E5;
background: #fff;
color: #333;
-webkit-writing-mode: horizontal-tb;
}
.liEmailTagChoiced
{
background: #FFF5BB;
border: 1px solid #F2E598;
border-bottom-left-radius: 6px;
border-top-right-radius: 6px;
padding: 2px 15px 3px 4px;
cursor: default;
display: block;
float: left;
margin: 2px 5px 2px 0;
position: relative;
}
.liEmailTagNew
{
padding: 2px 4px 1px 0;
}
.emailTagRemove
{
color:ActiveCaption;
cursor: pointer;
font-size: 12px;
font-weight: bold;
outline: medium none;
padding: 3px 0 2px 3px;
text-decoration: none;
position: absolute;
display: block;
top: 0;
right: 3px;
text-shadow: -1px -1px 0 rgba(150, 150, 0, 0.7);
}
JavaScript
//if enter, tab or space, add new value
$('.emailInputTag').keydown(function (e) {
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
if (key === 13 || key === 9 || key === 32) {
addEmail();
}
});
addEmail = function () {
var email = $('.emailInputTag').val().trim();
$('<li class="liEmailTagChoiced">' + email + '<a id="del" class="emailTagRemove">x</a></li>').insertBefore('.liEmailTagNew');
$('.emailInputTag').val("");
};
$('.emailTagRemove').click(function () {
var email = $(this).parents("li");
email.remove();
});