jquery - turning "autocomplete" to off for all forms (even ones not loaded yet)

You could bind a live event to the focus event and then change the attribute on that.

$(document).ready(function(){
    $(':input').live('focus',function(){
        $(this).attr('autocomplete', 'off');
    });
});

As of jQuery 1.7 jQuery.live was deprecated. This code would now look like:

$(document).ready(function(){
    $( document ).on( 'focus', ':input', function(){
        $( this ).attr( 'autocomplete', 'off' );
    });
});

The live event is now deprecated, you should us the on event instead. This will attach to every input in the DOM no matter if it's created yet or not. It will then add the autocomplete="off" attribute to that input.

$(document).ready(function() {
  $(document).on('focus', ':input', function() {
    $(this).attr('autocomplete', 'off');
  });
});

use jquery could don't be enough, because some browsers like chrome could load the 'autocomplete' saved data before document is ready ( $(document).ready)

jquery works like this

$('input, :input').attr('autocomplete', 'off');

but add manually autocomplete='off' to your input tags could be more efficient

Tags:

Forms

Jquery