As it is shown in this jsfiddle example when i change placeholder it triggers input event. I tested it on I.E 11 version but i guess that older versions have same problem. The other browsers does not behave like this. Is this I.E bug ? If so what is workaround for this problem on I.E ?
Here is html markup.
<input type="text" />
<button>Change PlaceHolder</button>
And here is javascript part.
var i = 0;
$('button').click(function(){
$('input').attr('placeholder','placeholder ' + i++);
});
$('input').bind('input',function(){
alert('input even occur');
});
Whenever the value of a form field changes, it fires a "change" event.
Use the dispatchEvent Method querySelector('input'); element. addEventListener('change', () => console. log('change')) const event = new Event('change'); element. dispatchEvent(event);
The input event fires when the value of an <input> , <select> , or <textarea> element has been changed. The event also applies to elements with contenteditable enabled, and to any element when designMode is turned on. In the case of contenteditable and designMode , the event target is the editing host.
checking if input is focused should be enough
$('input').bind('input',function(){
if($(document.activeElement) != $('input'))
return;
alert('input even occur');
});
this also "fixes" the input event being triggered without any actions when placeholder contains an accented character
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With