I want to apply font color to the string value in JavaScript. How do I?
I tried like below: I want the search text in red color.
$(document).ready(function() {
var defaultText="search";
defaultText.text.color="red";
});
you can only change the color of DOM element.In your case it is not DOM variable.It is a string you are not showing any where in the html.So it is not possible to apply color to that string .If you apply color also where you will see that color.
You can use span for holding string search and apply css to this span.
<span id="search"></span>
$(document).ready(function() {
$('#search').val('search').css('color','red');
});
defaultTextis a string, you cannot change the color of a string value