Input event triggered in Internet Explorer when replacing a placeholder

As jsfiddle shows in this example , when I change the placeholder, it fires an input event. I tested it on IE 11, but I think older versions have the same problem. Other browsers do not behave this way. Is this an IE bug? If so, is there a workaround for this problem on IE?

Here is the html markup.

<input type="text" />
<button>Change PlaceHolder</button>

And here is the javascript part.

var i = 0;
$('button').click(function(){
  $('input').attr('placeholder','placeholder ' + i++);
});

$('input').bind('input',function(){
    alert('input even occur');
});
+4
source share
1 answer

checking for input focus should be enough

$('input').bind('input',function(){
    if($(document.activeElement) != $('input'))
        return;
    alert('input even occur');
});

it also β€œcaptures” an input event that fires without any action when the placeholder contains an accented character

+2

Source: https://habr.com/ru/post/1524067/


All Articles