Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set html text color and size using javascript

Tags:

Suppose I have the following line of code in html, how to set the text color and size inside "MonitorInformation" DIV element in a programming way using Javascript in an easy way? Sorry for my stupid, I figured a long time but cannot figure out. :-(

<div id="MonitorInformation">Connecting...wait</div>

thanks in advance, George

like image 515
George2 Avatar asked Jul 27 '09 15:07

George2


People also ask

How do you change text color and size in HTML?

You can use a <basefont> tag to set all of your text to the same size, face, and color. The font tag is having three attributes called size, color, and face to customize your fonts. To change any of the font attributes at any time within your webpage, simply use the <font> tag.

How do you color text in JavaScript?

Use the String fontcolor() Method We can apply the fontcolor() method on any text string, and it returns the <font> HTML element with the color attribute.

How do you change the font Colour of your text in HTML?

To set the font color in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property color.


2 Answers

var elem = document.getElementById("MonitorInformation"); elem.innerHTML = "Setting different HTML content"; elem.style.color = "Red"; elem.style.fontSize = "large"; 
like image 124
AnthonyWJones Avatar answered Sep 18 '22 03:09

AnthonyWJones


var myDiv = document.getElementById("MonitorInformation");
myDiv.style.fontSize = "11px";
myDiv.style.color = "blue";

Take a look at the JavaScript Style Attributes

like image 23
Russ Cam Avatar answered Sep 21 '22 03:09

Russ Cam