For chrome :-webkit-autofill class works perfectly.
For a browser independent solution I what found was, the mouseleave event is fired whenever mouse is hovered over the browser's autofill dropdown. You can write handler on the input or its parent elements or event window. see the code below.
In HTML:
<div id="banner-message">
<div>
<input type="text" id="name" name="name" placeholder="name"/>
</div>
<div>
<input type="text" id="email" name="email" placeholder="email"/>
</div>
<div>
<input type="password" name="password" placeholder="password"/>
</div>
</div>
<div id="event-log"> </div>
In jQuery:
var banner = $("#banner-message")
var eventlog = $("#event-log");
var inputs = $("input");
//Following event fired when hovered over autofill dropdown,
banner.on("mouseleave", function(event) {
var targetid = event.target.id;
eventlog.html('Source id::'+targetid);
});
In the above code when the event is fired, event.target is the element from which the pointer is left and entered into dropdown.
one thing to note here is, you have to identify the correct way to detect mouseleave which is fired only when autofilled.The above solution worked for me.
see this fiddle: https://jsfiddle.net/nilesh_ramteke/nt7a1ruw/20/
Please configure your browser for autofill before trying above solution.