javascript - Code updates color but not the actual text? -
this chunk of code have updates color of text not actual text...
var lastwordtyped; var ele = document.queryselector("#my_text"); //code //... lastwordtyped = capitalizefirstletterofkeyword(lastwordtyped); lastwordtyped = lastwordtyped.fontcolor("blue"); ele.innerhtml = lastwordtyped; function capitalizefirstletterofkeyword(keyword) { var word; word = keyword.charat(0).touppercase() + keyword.slice(1); return word; }
when step through it, recognizing new string should doesnt update actual text new string, change color. can provide me reason why won't update it?
you haven't declared lastwordtyped, capitalizefirstletterofkeyword() gets 'undefined' input.
working demo here: http://jsfiddle.net/yc4mvm1n/1/
var lastwordtyped = "newword"; var ele = document.queryselector("#my_text"); lastwordtyped = capitalizefirstletterofkeyword(lastwordtyped); lastwordtyped = lastwordtyped.fontcolor("blue"); ele.innerhtml = lastwordtyped; function capitalizefirstletterofkeyword(keyword) { var word; word = keyword.charat(0).touppercase() + keyword.slice(1); return word; }
Comments
Post a Comment