Reputation: 135
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";
});
Upvotes: 0
Views: 759
Reputation: 40358
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.
Upvotes: 1
Reputation: 2971
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');
});
Upvotes: 0