Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off autocorrect of input using CSS or JavaScript

I need to turn off autocorrect with CSS/JavaScript. I cannot specify it in HTML because I generate multiple inputs over and over and this autocorrect red underline is very disturbing in my case.

I want to apply all these statements with CSS or JavaScript, but it seems that it's not possible.

<input autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />

Is there a way to generate multiple inputs without autocorrect underlining?

like image 850
Jsindl Avatar asked Oct 13 '18 20:10

Jsindl


2 Answers

If the inputs already exist and you are unable to set their attributes at the time they are generated, then you could use querySelectorAll and then loop through the resulting nodelist to set their attributes like so:

const inputs = document.querySelectorAll('input');

inputs.forEach(input => {
  input.setAttribute('autocomplete', 'off')
  input.setAttribute('autocorrect', 'off')
  input.setAttribute('autocapitalize', 'off')
  input.setAttribute('spellcheck', false)
})
<input />
<input />
<input />
<input />
like image 181
ksav Avatar answered Sep 25 '22 04:09

ksav


You can use something like this using JavaScript:

inputs = container.getElementsByTagName('input');
for (i = 0; i < inputs.length; ++i) {
  inputs[i].removeAttribute('autocomplete');
}
like image 40
Joe Fitzsimmons Avatar answered Sep 26 '22 04:09

Joe Fitzsimmons