You may like these:
- Responsive Personal Portfolio design
- Filterable Image Gallery with preview
- Random Password Generator
- Google Drive Link Converter
If you are unable to understand or felling difficulty understanding so you can check the source code and preview it as well.
Create Tag Input Box using HTML, CSS, and Javascript [Scource Code]
I hope you like it. If you want to create this. You'll have to create three files HTML, CSS with the extension for example:- For HTML - .HTML and for CSS - .css and for Javascript- .js just paste the given code in the files and don't forget to link the CSS and Javascript files to the HTML file.
Hurray! now you've created a tag input box. You can download files by clicking on the download button after downloading the file if you are facing any kind of problem feel free to ask me in the comment section and you can also contact me via e-mail. Thanks for giving your precious time for reading this blog. Here is the download button:-
Hi Ashutosh,
ReplyDeleteI think you should add the following the below two lines in your addTag() function in order to manage duplicate tags and empty tags when the input is any string ended with comma(,) and an enter key pressed to fed that input to your Tag input box,
if (!tag) return;
if (tags.includes(tag)) return;
modified addTag() will be like this
const addTag = (e) => {
if (e.key == 'Enter' || e.keyCode == 32) {
let tag = e.target.value.replace(/\s+/g, ' ');
if (tag.length > 1 && !tags.includes(tag)) {
tag.split(',').forEach((tag) => {
if (!tag) return;
if (tags.includes(tag)) return;
tags.push(tag);
createNewTag();
})
}
e.target.value = '';
}
if (e.target.value.length > 0) return
if (e.key == 'Backspace') {
tags = [...tags.slice(0, tags.length - 1)];
ul.querySelectorAll("li").forEach(li => li.remove());
createNewTag();
}
}
Thank you for taking the time to review the code and suggest improvements
Delete