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

木川 炎星 picture 木川 炎星 · Dec 15, 2010 · Viewed 9.1k times · Source

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?

Answer

Quentin picture Quentin · Dec 15, 2010

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.