Question

How can i change font color from an input value in jquery?

heres my code

<h3 id="quoteDiv"></h3>

 <input id="input1" type="text" onfocus="if(this.value == 'Valfri spelare') { this.value = ''; }" value="Valfri spelare"/>

 var quotes = ["(tjej1) exampletext!",];


var user1 = document.getElementById("input1").value;


//Sub in the usernames
                    var ind = Math.floor(Math.random() * quotes.length); //select random quote
                    var newquote = quotes[ind].replace("(tjej1)", user1);


var quotediv = document.getElementById("quoteDiv"); //get the div (or any other element) that you want to display the quote in
                    quotediv.innerHTML = newquote; //display your quote in the div.

How can i change the color of value from input1 (tjej1) to green and not the standard h3? I only want the value to change color:)

Thanks!

Was it helpful?

Solution

var newquote = quotes[ind].replace("(tjej1)", '<span style="color:green">'+user1+'</span>');

OTHER TIPS

You can style your h3 via CSS :

#quoteDiv{
    color: green;
}

Jquery keydown

$('#input').keydown(function(){

   $(this).css('color','green');

});

Jquery keyup

$('#input').keyup(function(){

   $(this).css('color','green');

});

Jquery chnage

$('#input').chnage(function(){

   $(this).css('color','green');

});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top