Last active
August 7, 2022 17:22
-
-
Save geraldotech/be6489f97c54138a0a8847d10f968c88 to your computer and use it in GitHub Desktop.
Listener Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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