Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to disable spellcheck in a textarea via JavaScript?

Is it possible to disable spellcheck in a textarea via JavaScript?

I've been looking at the HTML5 'spellcheck' attribute, and I can get it to work on its own. However, I'd like to be able to change this attribute via JavaScript.

After reading the documentation provided at the above link, I put together the following lines of code (snippets from a larger file; I know they won't work on their own):

document.querySelector("#editor").spellcheck = "false";

and

document.querySelector("#editor").spellcheck = "true";

But it doesn't seem to work. Have I made a mistake or misunderstood the documentation? (Unhelpfully, the JavaScript console in Google Chrome is not returning an error.) Or is there any other way to go about doing this?

like image 950
木川 炎星 Avatar asked Dec 15 '10 08:12

木川 炎星


1 Answers

You are setting it to the String "true" (which is a true value) and to the String "false" (which is also a true value).

Use Booleans, not Strings. Get rid of the quotes.

like image 67
Quentin Avatar answered Sep 19 '22 13:09

Quentin