JSFiddle - React, Tailwind, and code Playground
by jasonkylefrank
HTML
<span class="deletableInputWrapper">
<input type="text" class="deletableInput" />
<span class="inputDeleteButton">
<span class="inputDeleteImage"></span>
</span>
</span>
CSS
.deletableInputWrapper {
position: relative;
}
.inputDeleteButton {
position: absolute;
display: block;
top: 0px;
right: 0px;
height: 100%;
margin-right: 1px;
transition: all 0.1s ease;
}
.inputDeleteButton:hover {
background-color: gray;
}
.inputDeleteImage {
display: block;
margin: 3px 2px 2px 2px;
width: 16px;
height: 16px;
background: url('http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=4') 0 -690px;
cursor: pointer;
}
.deletableInput {
padding-right: 18px;
width: 225px;
border: 0;
border: 1px solid #aaa;
}
JavaScript
$(document).ready(function() {
$('.inputDeleteButton').click(function() {
$(this).prev('input').val('').focus();
});
});