Skip to content

Instantly share code, notes, and snippets.

@adamschwartz
Created December 30, 2016 17:05
Show Gist options
  • Select an option

  • Save adamschwartz/a27c414bbea90dad81cea7c47cbce8b7 to your computer and use it in GitHub Desktop.

Select an option

Save adamschwartz/a27c414bbea90dad81cea7c47cbce8b7 to your computer and use it in GitHub Desktop.
Automatically set CSS --value variable on inputs
inputSelector = 'textarea, input[type="text"], input[type="email"]';
for (input of document.querySelectorAll(inputSelector)) {
input.style.setProperty('--value', input.value);
}
document.addEventListener('input', e => {
var input = e.target;
input.style.setProperty('--value', input.value);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment