I have a Input box where I need to set the color of text which is being entered on the fly. I was not able to set the color using the content.style.color property. Here is the fiddle for highlighting word in input box
2 Answers
Hello!
content was not defined.
this should work for you
var text = document.getElementById('text');
text.addEventListener("keyup", function(event){
func(event)});
console.log(text);
var colors = ["red","green","blue","pink","maroon"];
var i = 0;
function func(e){
if(!(e.keyCode==32)){
var content = text.value;
document.getElementById('text').style.color = 'red';
}
}
<div class="highlight">
<input type="text" name="" value="" id="text">
</div>
Hope I helped you!
3 Comments
Tomasz Radwaski
Well, you coded it that way, you wrote that if keyCode != 32 the text color should change. I thought that you intended it
Tomasz Radwaski
Oh yea, sorry, It's late haha ^^