To implement the functionality shown in the code below, you can simply integrate it into your website. The code is compatible with all web browsers.
Embed the following HTML:
<span class="surround">
<span class="tagsh"> Name </span>
</span>
Integrate JQuery as follows:
var clearIcon ='<span id="icon_clear">X</span>';
$('<input type="input" class="textbox"/>'+clearIcon).appendTo('.surround')
.keyup(
function(e){
var $dad = $($(this).parent());
$(this).val().length>0?
$('#icon_clear').fadeIn(300).click(function() {
$('.textbox').val('');}):
$('#icon_clear').fadeOut(300);
if (e.keyCode in {13:"enter",32:"space"}){
var text = $(this).val();
$('#icon_clear').remove();
$dad.append($('<span class="tag"><span class="plus"></span><span class="minus"></span> '+text+'</span>'));
$dad.append($(this).val("").hide().show("slow").focus());
$dad.append(clearIcon);
} ;});
Apply the CSS styles listed below:
.textbox{
width:70px;
border:1px dotted #ccc;
margin: 0 5px;
padding-right:18px;
}
span#icon_clear{
display:none;
cursor:pointer;
color:#38468F;
position:relative;
right:21px;
}
span#icon_clear:hover{
color:#ccc;
}
For a demo and further customization options, visit the JSFiddle link provided: http://jsfiddle.net/ketan156/7PnKS/98/