Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vladimirlukyanov/a990efb823f7522db6ee8823861b17c1 to your computer and use it in GitHub Desktop.
Save vladimirlukyanov/a990efb823f7522db6ee8823861b17c1 to your computer and use it in GitHub Desktop.
Listen for input change programmatically | Vanilla JS
<script type="text/javascript">
let event = new Event('change');
let inputBox = document.querySelector("#shipping_postcode");
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(inputBox), 'value');
Object.defineProperty(inputBox, 'value', {
set: function(t) {
if(t === '') return;
return descriptor.set.apply(this, arguments);
},
get: function() {
return descriptor.get.apply(this);
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment