6

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');
});
Freshblood
  • 6,285
  • 10
  • 59
  • 96
  • please read about input event at : https://developer.mozilla.org/en-US/docs/Web/Reference/Events/input – Shyam Jan 28 '14 at 13:04
  • if this issue is on earlier versions of IE you may use placeholder.js – Green Wizard Jan 28 '14 at 13:26
  • 1
    I have the same problem, changing placeholder does indeed trigger input event. in IE 10 and 11, previous IE do not support placeholder natively so don't have the problem. – Cactusbone Oct 13 '14 at 10:08
  • 1
    similar question http://stackoverflow.com/questions/19289396/jquery-input-event-fired-on-placeholder-in-ie – Cactusbone Oct 13 '14 at 10:40
  • 1
    It is an IE 10/11 bug: https://connect.microsoft.com/IE/feedback/details/810538/ie-11-fires-input-event-on-focus – Ian Kemp Oct 15 '15 at 14:06

1 Answers1

3

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

Cactusbone
  • 1,056
  • 8
  • 20