av1000
av1000

Reputation: 135

font color for string value in javascript

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: 757

Answers (2)

PSR
PSR

Reputation: 40318

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

r.piesnikowski
r.piesnikowski

Reputation: 2951

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

Related Questions