Skip to content

Instantly share code, notes, and snippets.

@geraldotech
Last active August 7, 2022 17:22
Show Gist options
  • Save geraldotech/be6489f97c54138a0a8847d10f968c88 to your computer and use it in GitHub Desktop.
Save geraldotech/be6489f97c54138a0a8847d10f968c88 to your computer and use it in GitHub Desktop.
Listener Search
//html
<input type="text" />
<div id="esu">
<span id="res"></span>
</div>
//css
#esu{
display: none;
background: red;
width: fit-content;
}
//js
input = document.querySelector("input");
input.addEventListener("input", function(){
res = document.getElementById("res");
esu = document.getElementById("esu");
const str = this.value.toLowerCase();
console.log(str)
const writtenA = {
0:'zero',
1:'one',
'tr':"Trigg",
'ti':"tipo",
'ty':"TypeScript",
'Type':"TypeScript",
}
const get = num => {
return writtenA[num] || "other";
}
console.log(get(str));
res.innerHTML = get(str);
esu.style.display = 'block';
if(this.value.length == 0){
res.innerHTML = '';
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment