Skip to content

Instantly share code, notes, and snippets.

@alonbardavid
Last active September 2, 2019 11:43
Show Gist options
  • Save alonbardavid/65bfd0447739bb6ca5003acf6ebabcff to your computer and use it in GitHub Desktop.
Save alonbardavid/65bfd0447739bb6ca5003acf6ebabcff to your computer and use it in GitHub Desktop.
function myComponent(selector,label,value,onChange){
let element = document.querySelector(selector);
element.innerHTML=```
<div class="my-element">
<label>${label}</label>
<input></input>
</div>
```
let input = element.querySelector('input');
input.value = value;
input.addEventListener('keydown', e=>{
e.preventDefault(); //stops the input from accepting the change
input.value = onChange(input.value + e.key);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment