I am developing a small spelling program and I will need to change the color of the misspelled letter. This is what I have tried. This code detects a misspelling but it does not change the color of the misspelled letter:
$("#inputfield").keyup(function () {
var inputstring = document.getElementById("inputfield").value;
var inputlng = inputstring.length;
if (stavningsord.indexOf(inputstring)!=0) {
// alert ("Misspell");
var html = document.getElementById("inputfield");
var containedhtml = html.innerHTML;
html.innerHTML = containedhtml.substr(0, containedhtml.length-1) + "<span style='color: red'>" + html.innerHTML.substr(-1) + "</span>";
// $("#inputfield").html = (inputstring.substr(0, inputstring.length-1) + "<span style='color: red'>" + $(this).html().substr(-1) + "</span>");
alert ("Misspell");
}
});
Any help is appreciated!