knowledgefaculty
Coder
I want to some tags by default witch show up time of open the page. This code normally working fine as add tags but when I trying some tags default such as java, html, php etc then code normally working but no show up default tags. Below is my code, please advice me how to do
I can't do it when I trying. I added it like tag = ["coding", "java"]; but no result I got. How to include by some tags default? I am not much experience in the field. I will be grateful if anybody help me.
Code:
const removeTag = (event) => {
if (event.target.classList.contains('tag-close')) {
event.target.parentElement.remove();
}
}
const addTag = (event) => {
if (event.keyCode === 13) {
const input = document.getElementById('input')
const tagsContainer = document.querySelector('.tags-container');
const value = event.target.value;
const spanElement = document.createElement('span');
spanElement.innerHTML = `
<span class="tag-text">${value}</span>
<span class="tag-close"> ⌫ </span>
`
spanElement.classList.add('tag');
tagsContainer.appendChild(spanElement);
input.value = '';
tag = ["coding", "java"];
}
}
window.onload = () => {
const tagsContainer = document.querySelector('.tags-container');
tagsContainer.addEventListener('click', removeTag);
}
I can't do it when I trying. I added it like tag = ["coding", "java"]; but no result I got. How to include by some tags default? I am not much experience in the field. I will be grateful if anybody help me.