JavaScript: String Fontcolor() Method - TechOnTheNet

Advertisement

TechOnTheNet Logo
  1. Home
  2. JavaScript
  • Databases
  • SQL
  • Oracle / PLSQL
  • SQL Server
  • MySQL
  • MariaDB
  • PostgreSQL
  • SQLite
  • MS Office
  • Excel
  • Access
  • Word
  • Web Development
  • HTML
  • CSS
  • JavaScript
  • Color Picker
  • Programming
  • C Language
  • More
  • ASCII
  • Unicode
  • Linux
  • UNIX
  • Techie Humor

Advertisement

clear filter right caret

JS Basics

  • Comments
  • Console Log
  • Literals
  • Operators
  • Reserved Words
  • Variables
right caret

JS Loops/Conditionals

  • break
  • continue
  • do-while loop
  • for loop
  • for-in loop
  • if-else
  • switch
  • while loop
down caret

JS String Methods

  • anchor
  • big
  • blink
  • bold
  • charAt
  • charCodeAt
  • codePointAt
  • concat
  • endsWith
  • fixed
  • fontcolor
  • fontsize
  • fromCharCode
  • fromCodePoint
  • includes
  • indexOf
  • italics
  • lastIndexOf
  • length
  • link
  • localeCompare
  • match
  • normalize
  • padEnd
  • padStart
  • repeat
  • replace
  • search
  • slice
  • small
  • split
  • startsWith
  • strike
  • sub
  • substr
  • substring
  • sup
  • toLocaleLowerCase
  • toLocaleUpperCase
  • toLowerCase
  • toString
  • toUpperCase
  • trim
  • trimEnd
  • trimStart
  • valueOf
right caret

JS Number Methods

  • EPSILON
  • isFinite
  • isInteger
  • isNaN
  • isSafeInteger
  • MAX_SAFE_INTEGER
  • MAX_VALUE
  • MIN_SAFE_INTEGER
  • MIN_VALUE
  • NaN
  • NEGATIVE_INFINITY
  • parseFloat
  • parseInt
  • POSITIVE_INFINITY
  • toExponential
  • toFixed
  • toLocaleString
  • toPrecision
  • toString
  • valueOf
right caret

JS Math Functions

  • abs
  • acos
  • acosh
  • asin
  • asinh
  • atan
  • atan2
  • atanh
  • cbrt
  • ceil
  • clz32
  • cos
  • cosh
  • E
  • exp
  • expm1
  • floor
  • fround
  • hypot
  • imul
  • LN10
  • LN2
  • log
  • log10
  • LOG10E
  • log1p
  • log2
  • LOG2E
  • max
  • min
  • PI
  • pow
  • random
  • round
  • sign
  • sin
  • sinh
  • sqrt
  • SQRT1_2
  • SQRT2
  • tan
  • tanh
  • trunc
right caret

JS Array Methods

  • concat
  • copyWithin
  • entries
  • every
  • fill
  • filter
  • find
  • findIndex
totn JavaScript JavaScript: String fontcolor() method

This JavaScript tutorial explains how to use the string method called fontcolor() with syntax and examples.

Description

In JavaScript, fontcolor() is a string method that is used to create the HTML <font> element and specify a font color. Because the fontcolor() method is a method of the String object, it must be invoked through a particular instance of the String class.

Syntax

In JavaScript, the syntax for the fontcolor() method is:

string.fontcolor(color_value);

Parameters or Arguments

color_value It is a color name or color value that will be used as the color attribute for the <font> element.

Returns

The fontcolor() method returns a string containing a <font> element. The value of the color_value parameter is used as the color attribute for the <font> element.

Note

  • The fontcolor() method does not change the value of the original string.

Example

Let's take a look at an example of how to use the fontcolor() method in JavaScript.

For example:

var totn_string = 'TechOnTheNet'; console.log(totn_string.fontcolor('blue'));

In this example, we have declared a variable called totn_string that is assigned the string value of 'TechOnTheNet'. We have then invoked the fontcolor() method of the totn_string variable to return a string that contains the HTML <font> element with a font color.

We have written the output of the fontcolor() method to the web browser console log, for demonstration purposes, to show what the fontcolor() method returns.

The following will be output to the web browser console log:

<font color="blue">TechOnTheNet</font>

As you can see, the fontcolor() method created a string that contains a <font> element. The value of the totn_string variable (which is 'TechOnTheNet') is enclosed within the <font> and </font> tags. The string value of 'blue' that was passed into the fontcolor() method as a parameter is used as the color attribute for the <font> element.

Specifying a Hexadecimal Value

You can also use a Hexadecimal color value as a parameter for the fontcolor() method.

For example:

var totn_string = 'TechOnTheNet'; console.log(totn_string.fontcolor('#0000FF'));

The following will be output to the web browser console log:

<font color="#0000FF">TechOnTheNet</font>

In this example, the Hexadecimal representation of the color blue (which is #0000FF) is used as the color attribute for the <font> element.

previousNEXT: fontsizenext Share on:

Advertisement

Home | About Us | Contact Us | Testimonials | Donate

While using this site, you agree to have read and accepted our Terms of Service and Privacy Policy.

Copyright © 2003-2024 TechOnTheNet.com. All rights reserved.

Từ khóa » Html Color Text Javascript