javascript - How do I prevent both my if statements running the first time? -
quick question i'm drawing blank, if have event listener contains 2 if statements on first time round both true don't want both of them execute how prevent this? can break on first conditional or that?
js
var input = document.queryselector('.js-input'), output = document.queryselector('.js-output'); input.addeventlistener('keydown', function (event) { if (this.value.length === 0) { console.log('run once'); } if (this.value === '') { console.log('this empty show hint') } });
var input = document.queryselector('.js-input'), output = document.queryselector('.js-output'); var firsttimecallbackrun= true; input.addeventlistener('keydown', function (event) { if (this.value.length === 0) { console.log('run once'); if(firsttimecallbackrun) { firsttimecallbackrun = false; return; } } if (this.value === '') { console.log('this empty show hint') } });
Comments
Post a Comment