Javascript change font color

javascript change font color based on value
javascript change font color on click
javascript change font color of div
javascript change input text color
javascript color object
how to change font color in javascript alert message
javascript change background color
change text color java

I need to change the font color.

I have the following:

   var clr="green";

    <font color=clr>' + onlineff + ' </font>

The font color does not change to green. Just wondering how this could be fixed.

Don't use <font color=. It's a really old fashioned way to style text and some browsers even don't even support it anymore.

caniuse lists it as obsolete, and strongly recommends not using the <font> tag. The same is with MDN

Do not use this element! Though once normalized in HTML 3.2, it was deprecated in HTML 4.01, at the same time as all elements related to styling only, then obsoleted in HTML5.

Starting with HTML 4, HTML does not convey styling information anymore (outside the element or the style attribute of each element). For any new web development, styling should be written using CSS only.

The former behavior of the element can be achieved, and even better controlled using the CSS Fonts CSS properties.

If we look at when the 4.01 standard was published we see it was published in 1999

where <font> was officially deprecated, meaning it is still supported but shouldn't be used anymore as it will go away in the newer standard.

And in the html5 standard released in August 2014 it was deemed obsolete and non conforming.

To achieve the desired effect use spans and css:

function givemecolor(thecolor,thetext)
    return '<span style="color:'+thecolor+'">'+thetext+'</span>';
document.write(givemecolor('green',"Hello, I'm green"));
document.write(givemecolor('red',"Hello, I'm red"));
body {
  background: #333;
  color: #eee;

HTML DOM Style color Property, The fontcolor() method is used to display a string in a specified color. This method returns the string embedded in the <font> tag, like this: <font color="​colorvalue">  Javascript Web Development Front End Technology To change the font color of a text, use the fontcolor() method. This method causes a string to be displayed in the specified color as if it were in a <font color="color"> tag.

Consider changing your markup to this:

<span id="someId">onlineff</span>

Then you can use this script:

var x = document.getElementById('someId'); = '#00FF00';

see it here:

JavaScript String fontcolor() Method, Don't use <font color= . It's a really old fashioned way to style text and some browsers even don't even support it anymore. caniuse lists it as  You can use the HTML tag in order to apply font size, font color in one line on JavaScript, as well as you can use.fontcolor() method to define color,.fontsize() method to define the font size,.bold() method to define bold, etc. These are called JavaScript Built-in Functions.

Html code

<div id="coloredBy">
    Colored By Santa

javascript code

document.getElementById("coloredBy").style.color = colorCode; // red or #ffffff

I think this is very easy to use

Javascript change font color, You set the style per element and not by its content: function init() { document.​getElementById("about").style.color = 'blue'; }. With innerHTML  JavaScript – Change Text Font Color in HTML Change font color by style of id of tag with color attribute in javascript.

Try like this:

var clr = 'green';
var html = '<font color="' + clr + '">' + onlineff + ' </font>';

This being said, you should avoid using the <font> tag. It is now deprecated. Use CSS to change the style (color) of a given element in your markup.

Change text color with Javascript?, How do I change the color of something in JavaScript? Change text color with Javascript? Ask Question Asked 6 years, 10 months ago. Active 9 months ago. Viewed 89k times 9. 2. I want to change the color of a title when a button is clicked. This is my code, but it's not working and I can't figure out why not

How to Change Font Sizes with JavaScript (, The following example uses the fontcolor() method to change the color of a string by producing a string with the HTML <font> tag. var worldString  Value Description; color: Specifies the color of the text. Look at CSS Color Values for a complete list of possible color values: initial: Sets this property to its default value.

String.prototype.fontcolor(), In the following web document, the fontcolor() method is used to change the color of a string. The method produces same output as html : <font  Sets the font-style: variant: Sets the text in a small-caps font: weight: Sets the boldness of the font: size: Sets the size of the font: lineHeight: Sets the distance between lines: family: Sets the font face: caption: The font used for captioned controls (like buttons, drop-downs, etc.) icon: The font used to label icons: menu: The font used

JavaScript fontcolor() Method : String Object, How to change text color on click using JavaScript? Example. Change Font Color Green Change Font Color Red. Learn the test-driven development approach  Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.

How to change text color on click using JavaScript , In JavaScript, fontcolor() is a string method that is used to create the HTML element The fontcolor() method does not change the value of the original string​. In the following web document, the fontcolor() method is used to change the color of a string. The method produces same output as html : <font color="maroon">Welcome Viewers</font> and so on.

  • presentational tags like <font>, <center>,... should be avoided at all (markup should be used for semantic purpose only). Use style attribute instead
  • @BenBarden That's an apostrophe.
  • it's not deprecated it's removed (and there is no color attribute either).
  • font is deprecated since html 4.01