I want to incorporate tags similar to stackoverflow on my website. Users will be able to create tags for filtering results, searching, showcasing expertise, and more.
I have managed to create tags, but I am struggling to display them inside an input box like stackoverflow. The issue lies with the margin between tags. Every time a tag is created, it appears aligned but without any space or margin. Currently, all tags are displayed inline without any separation.
The jQuery code I have experimented with is:
$(function () {
$("#inputtext").keypress(function (e) {
var valueofinput = $(this).val();
if (e.which == 13) {
$('.tag').html(valueofinput);
$('.tag').show();
}
});
$('.tag').click(function () {
$(this).hide();
});
});
I also tried displaying the tags within an input tag like this:
if(e.which==13)
{
$("#inputtext").val().addClass('tag').css('display','inline-block');
}
if(e.which==32) //for space
{
$('.tag').css('margin-left','5px');
}
Unfortunately, this approach did not yield the desired result.