How To Change Font Color Of HTML Element In JavaScript?

Skip to content C++ Java PHP Python Kotlin Swift JavaScript Golang
  • JavaScript
  • JavaScript Tutorial
  • JavaScript Comments
  • JavaScript Primitive Datatypes
  • JavaScript - Arithmetic Operators
    • JavaScript – Addition Operator
    • JavaScript – Subtraction Operator
    • JavaScript – Multiplication Operator
    • JavaScript – Division Operator
    • JavaScript – Modulus Operator
    • JavaScript – Increment Operator
    • JavaScript – Decrement Operator
  • JavaScript - Comparison Operators
    • JavaScript Equal-to Operator
    • JavaScript Equal Value Equal Type Operator
    • JavaScript Not-equal Operator
    • JavaScript Greater-than Operator
    • JavaScript Less-than Operator
    • JavaScript Greater-than or Equal to Operator
    • JavaScript Less-than or Equal to Operator
  • JavaScript - Logical Operators
    • JavaScript – AND Operator
    • JavaScript – OR Operator
    • JavaScript – NOT Operator
  • JavaScript - If Else
  • JavaScript - Switch
  • JavaScript - Loops
    • JavaScript For Loop
    • JavaScript For-in Loop
    • JavaScript For-of Loop
    • JavaScript While Loop
    • JavaScript Do-While Loop
    • JavaScript Break
    • JavaScript Continue
  • JavaScript - Try Catch
    • JavaScript SyntaxError: Invalid shorthand property initializer
  • JavaScript - Arrays
    • JavaScript – Create array
    • JavaScript – Array length
    • JavaScript – Access elements of array using index
    • JavaScript – Loop over an Array
    • JavaScript – Array forEach()
    • JavaScript – Join elements of array to a string
    • JavaScript – Add element to starting of array
    • JavaScript – Add element to end of array
    • JavaScript – Remove first element in array
    • JavaScript – Remove last element in array
    • JavaScript – Remove element at specific index
    • JavaScript – Concatenate arrays
    • JavaScript – Sort a numeric array
    • JavaScript – Sort a string array
    • JavaScript – Slice array
    • JavaScript – Reverse array
    • JavaScript – Find index of element in array
    • JavaScript – Filter array
    • JavaScript – Numeric array
    • JavaScript – String array
    • JavaScript – Boolean array
    • JavaScript – Object array
    • JavaScript – Heterogenous array
  • JavaScript - Strings
    • Basics
    • JavaScript – Create a string
    • JavaScript – Create empty string
    • JavaScript – Compare strings
    • JavaScript – Count number of words in string
    • JavaScript – Find string length
    • JavaScript – Iterate over characters of a string
    • JavaScript – Multi-line strings
    • JavaScript – Substring of a string
    • Checks
    • JavaScript – Check if string is empty
    • JavaScript – Check if strings are equal
    • JavaScript – Check if strings are equal ignoring case
    • JavaScript – Check if string contains specified substring
    • JavaScript – Check if string starts with specific string
    • JavaScript – Check if string ends with specific string
    • JavaScript – Check if string starts with http
    • JavaScript – Check if string starts with an uppercase
    • Updates
    • JavaScript – Concatenate strings
    • JavaScript – Repeat string N times
    • Split Operations
    • JavaScript – Split string
    • JavaScript – Split string by a character
    • JavaScript – Split string by comma
    • JavaScript – Split string by single space
    • JavaScript – Split string by new line
    • JavaScript – Split string by any white space character
    • Transformations
    • JavaScript – Reverse a string
    • JavaScript – String to lowercase
    • JavaScript – String to uppercase
    • JavaScript – Trim string
    • JavaScript – Join elements of string array with delimiter string
    • JavaScript – Join elements of string array with comma
    • Delete Operations
    • JavaScript – Remove first character of string
    • JavaScript – Remove last character of string
    • Search
    • JavaScript – Find the Index of substring in string
    • Matchings
    • JavaScript – Find all the matches of a Regular Expression in a string
    • Replacements
    • JavaScript – Replace a substring in string
    • JavaScript – Replace all occurrences of a substring in string
    • Sorting
    • JavaScript – Sort string array lexicographically
    • JavaScript – Sort strings in array based on length
    • Filtering
    • JavaScript – Filter string array based on string length
    • JavaScript – Remove empty strings from string array
    • Conversions
    • JavaScript – Convert string to integer
    • JavaScript – Convert string to float
    • JavaScript – Convert array of characters to string
    • JavaScript – Convert string to array of characters
    • JavaScript – Convert Comma-Separated String into Array
  • JavaScript - Maps
    • JavaScript – Create a Map
    • JavaScript – Insert a key-value to Map
    • JavaScript – Get Map size
    • JavaScript – Get value for specific key in Map
    • JavaScript – Delete specific key from Map
    • JavaScript – Check if Map has specific key
    • JavaScript – Iterate over Map
    • JavaScript – Map forEach()
  • JavaScript - Sets
    • JavaScript – Create Set
    • JavaScript – Create an empty Set
    • JavaScript – Set size/length
    • JavaScript – Add element to Set
    • JavaScript – Delete element from Set
    • JavaScript – Check if Set contains specific element
    • JavaScript – Iterate over Set
    • JavaScript – Set forEach()
    • JavaScript – Convert Array into Set
  • JavaScript - Classes
  • JavaScript - Date
  • JavaScript - Date Methods
  • JavaScript in HTML Docuemnt
  • JavaScript Howtos - HTML Element
    • How to get Attributes of HTML Element Element in JavaScript?
    • How to Insert Element in Document after Specific HTML Element Element using JavaScript?
    • How to get Number of Child Elements of this HTML Element in JavaScript?
    • How to Get Children of an HTML Element in JavaScript?
    • How to Iterate over Children of HTML Element in JavaScript?
    • How to Get Class Names of an HTML Element as List in JavaScript?
    • How to Get Class Names of an HTML Element as String in JavaScript?
    • How to Get Height of an HTML Element in JavaScript?
    • How to Get Width of an HTML Element in JavaScript?
    • How to Get First Child of an HTML Element in JavaScript?
    • How to Get Last Child of an HTML Element in JavaScript?
    • How to Get Next Sibling of an HTML Element in JavaScript?
    • Modify Style of HTML Elements
    • JavaScript – Change style of HTML element – HTMLElement.style
    • How to Change the Background Color of HTML Element in JavaScript?
    • How to Change Font Color of HTML Element in JavaScript?
    • How to Change the Border of HTML Element in JavaScript?
    • How to Change Bottom Border of HTML Element in JavaScript?
    • How to Change Top Border of HTML Element in JavaScript?
    • How to Change Left Border of HTML Element in JavaScript?
    • How to Change Right Border of HTML Element in JavaScript?
    • How to Change Border Color of HTML Element in JavaScript?
    • How to Change Border Width of HTML Element in JavaScript?
    • How to Change Border Style of HTML Element in JavaScript?
    • How to Change Border Radius of HTML Element in JavaScript?
    • How to Change Font Size of HTML Element in JavaScript?
    • How to Change Font Family of HTML Element in JavaScript?
    • How to Change Font Weight of HTML Element in JavaScript?
    • How to Change Opacity of HTML Element in JavaScript?
    • How to Change Width of HTML Element in JavaScript?
    • How to Change Height of HTML Element in JavaScript?
    • How to Clear Inline Style of HTML Element in JavaScript?
    • How to Hide HTML Element in JavaScript?
    • How to Underline Text in HTML Element in JavaScript?
    • How to Change Text in HTML Element to Bold in JavaScript?
    • How to Change Text in HTML Element to Italic in JavaScript?
    • How to Change Padding of HTML Element in JavaScript?
    • How to Change Margin of HTML Element in JavaScript?
  • JavaScript Howtos - Paragraph
    • How to Change the Background Color of Paragraph in JavaScript?
    • How to Change Font Color of Paragraph in JavaScript?
    • How to Change the Border of Paragraph in JavaScript?
    • How to Change Bottom Border of Paragraph in JavaScript?
    • How to Change Top Border of Paragraph in JavaScript?
    • How to Change Left Border of Paragraph in JavaScript?
    • How to Change Right Border of Paragraph in JavaScript?
    • How to Change Border Color of Paragraph in JavaScript?
    • How to Change Border Width of Paragraph in JavaScript?
    • How to Change Border Style of Paragraph in JavaScript?
    • How to Change Border Radius of Paragraph in JavaScript?
    • How to Change Font Size of Paragraph in JavaScript?
    • How to Change Font Family of Paragraph in JavaScript?
    • How to Change Font Weight of Paragraph in JavaScript?
    • How to Change Opacity of Paragraph in JavaScript?
    • How to Change Width of Paragraph in JavaScript?
    • How to Change Height of Paragraph in JavaScript?
    • How to Clear Inline Style of Paragraph in JavaScript?
    • How to Hide Paragraph in JavaScript?
    • How to Underline Text in Paragraph in JavaScript?
    • How to Change Paragraph Text to Bold in JavaScript?
    • How to Change Paragraph Text to Italic in JavaScript?
    • How to Change Padding of Paragraph in JavaScript?
    • How to Change Margin of Paragraph in JavaScript?
  • JavaScript Howtos - Div
    • How to Change the Background Color of Div in JavaScript?
    • How to Change Font Color of Div in JavaScript?
    • How to Change the Border of Div in JavaScript?
    • How to Change Bottom Border of Div in JavaScript?
    • How to Change Top Border of Div in JavaScript?
    • How to Change Left Border of Div in JavaScript?
    • How to Change Right Border of Div in JavaScript?
    • How to Change Border Color of Div in JavaScript?
    • How to Change Border Width of Div in JavaScript?
    • How to Change Border Style of Div in JavaScript?
    • How to Change Border Radius of Div in JavaScript?
    • How to Change Font Size of Div in JavaScript?
    • How to Change Font Family of Div in JavaScript?
    • How to Change Font Weight of Div in JavaScript?
    • How to Change Opacity of Div in JavaScript?
    • How to Change Width of Div in JavaScript?
    • How to Change Height of Div in JavaScript?
    • How to Clear Inline Style of Div in JavaScript?
    • How to Hide Div in JavaScript?
    • How to Underline Text in Div in JavaScript?
    • How to Change Text in Div to Bold in JavaScript?
    • How to Change Text in Div to Italic in JavaScript?
    • How to Change Padding of Div in JavaScript?
    • How to Change Margin of Div in JavaScript?

JavaScript – Change Font Color of HTML Element

To change the font color of a HTML Element using JavaScript, get reference to this HTML element, and assign required color value to the element.style.color property.

In the following example, we will change the font color of HTML Element with id "myElement" to the color "#FF0000", in JavaScript, using element.style.color property.

example.html

</> Copy <!DOCTYPE html> <html lang="en"> <head> <style> #myElement { border:1px solid #CCC; width:100px; height:100px; } </style> <meta charset="utf-8"> </head> <body> <h2>Change Font Color of HTML Element in JavaScript</h2> <div id="myElement">Hello World!</div> <br> <button type="button" onclick="changeStyle()">Click Me</button> <script> function changeStyle(){ var element = document.getElementById("myElement"); element.style.color = "#FF0000"; } </script> </body> </html>

Conclusion

In this JavaScript Tutorial, we learned how to change the font color of a HTML Element using JavaScript.

❮ Previous Next ❯

How-Tos Featured Video

Popular Courses

SAP

  • SAP FI
  • SAP CO
  • SAP HR
  • SAP SD
  • SAP PS
  • SAP ABAP
  • SAP MM
  • SAP PP
  • SAP PM
  • SAP GRC

CRM

  • Salesforce
  • Salesforce Admin
  • Salesforce Developer
  • Visualforce
  • Informatica

SAP Resources

  • SAP Tables
  • SAP Tcodes

Apache

  • Hadoop
  • Kafka Tutorial
  • MXNet
  • OpenNLP
  • PDFBox
  • Spark Tutorial
  • Tomcat Tutorial

GUI

  • JavaFX
  • Python Tkinter

Programming

  • C#
  • C++
  • Dart
  • Golang
  • Java
  • Julia
  • Kotlin
  • Python
  • R
  • Scala
  • Swift
  • TypeScript

    Databases

  • MongoDB
  • MySQL
  • PostgreSQL

Mobile

  • Android Compose
  • Flutter
  • Kotlin Android
  • SwiftUI

Linux

  • Bash Script

Web & Server

  • PHP
  • HTML
  • CSS
  • JavaScript
  • NGINX
  • NodeJS

Testing

  • Selenium Java

Learning

  • Maths
  • Physics
  • Chemistry
  • Units
  • Definitions
  • Fashion
  • General Knowledge
  • How-To

Từ khóa » Html Color Text Javascript