alsco77 alsco77 - 9 days ago 7
HTML Question

Add spellcheck to non-contenteditable div?

Is it possible to run the browser's in built spell checker on divs which aren't contenteditable? The below code works for checking spelling, but the div must be contenteditable and the spell check is only executed once the div is put into focus.

<div contenteditable="true" spellcheck="true">
This paragraph gets spell checked when the div comes into focus
</div>


I want to display a full page of html and have the red squiggly lines underneath all the mis spelled words

Answer

I used the following code to apply the spell checker using jquery-2.2.1.js. I made all divs contenteditable and then after view loaded ran:

$('.content-container').each((i, el: any) => {
    $(el)[0].focus();
    $(el)[0].setAttribute('contenteditable', 'false');            
})  
Comments