Skip to content

Instantly share code, notes, and snippets.

@robertsheacole
Last active December 9, 2017 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertsheacole/b76c3afd999e49cb1c2e4a5320f09c97 to your computer and use it in GitHub Desktop.
Save robertsheacole/b76c3afd999e49cb1c2e4a5320f09c97 to your computer and use it in GitHub Desktop.
2 Way Binding with Vanilla JavaScript
function bind(items, event) {
items.forEach(item => {
item.addEventListener(event, e => {
items.forEach(otherItem => {
otherItem.value = e.target.value;
otherItem.innerHTML = e.target.value;
});
});
});
}
// Pass in items as and array of DOM elements that you want to bind together.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment