• Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
    • Tips
    • QA’s
    • Misc
  • Course
  • Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
    • Tips
    • QA’s
    • Misc
  • Course
  • #News
  • #APPS
  • #Apple WWDC
  • #Google I/O
  • #Microsoft Ignite
  • #Let’s Talk
  • #Advertise

MyCodeTips mycodetips-newlogocopy1

  • Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
    • Tips
    • QA’s
    • Misc
  • Course
Javascript

How to change colour of font using javascript

change colour of font

Those two parentheses denote the method and hold instructions on what should happen. For instance:

<SCRIPT LANGUAGE=”javascript”>
document.write(‘<FONT COLOR=green>Green Text</FONT>’)
</SCRIPT>

That script will produce this: Green Text
See what’s happening? The document is being acted upon by the method “write.” Inside the ( and the ) is what should be written to the page. In this case, green text.

Also Read : Tips to avoid JavaScript Mistakes

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.

Here is a list of JavaScript some useful functions:

  • .big()
  • .small()
  • .italics()
  • .fixed()
  • .strike()
  • .sup()

The below functions require parameters:

  • .fontsize() //e.g.: the size to be applied in number .fontsize(4)
  • .fontcolor(“”) //e.g.: the color to be applied in string .fontcolor(“red”)
  • .txt.link(“”) //e.g.: the url to be linkable as string .link(“www.test.com”)
  • Remember the syntax is: string.functionName() e.g.:
  • var txt = “Hello World!”;
    txt.bold

The result will be: Hello World!

You can use multiple functions in one line, adding one next to the other. e.g.:

“10/22/2018”.fontcolor(“red”).fontsize(4).bold()

The following is an example how I used it on my JavaScript code to change font (color, size, bold) using both HTML tags and JavaScript functions:

function init() { 
document.getElementById("about").style.color = 'blue';
}
function init() { 
about = document.getElementById("about");
about.style.color = 'blue';
}
$(document).ready(function(){
$('#about').css({'background-color':'black'}); 
});
function givemecolor(thecolor,thetext)
{
return ''+thetext+'';
}
document.write(givemecolor('green','I\'m an apple'));
document.write(givemecolor('yellow','and I\'m a banana'));
  • Click to share on Reddit (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • More
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - September 24, 2013 - 1323 Views
Tags | javascript, SCRIPT
AUTHOR
Ranjan

This website is basically about of what we learnt from my years of experience as a software engineer on software development specifically on mobile application development, design patterns/architectures and its changing scenarios, security, troubleshooting, tools, tips&tricks and many more.

You Might Also Like

mycodetips wordpress

Tips For Every WordPress Developer

December 16, 2013
Javascript-CheatSheet

JavaScript Cheatsheets or Basics Reference

July 23, 2021
js-cheatsheets-advance-methods

JavaScript Methods & Properties CheatSheets

July 25, 2021
Next Post
Previous Post

Support us

Subscribe for updates

Join 8,278 other subscribers

Latest Posts

  • Exploring Single Point Failure
    Exploring Single Point Failures: Causes and Impacts
  • primitive-datatypes-new
    Exploring the Pros and Cons of Primitive Data Types
  • best practice clean code
    Essential Coding Standards and Best Practices for Clean Code
  • YT-Featured-Templates--lld
    What Business Problems Solves in Low Level Design (LLD)
  • SRP-SingleResopnsibility
    SRP : Single Responsibility Principle in Swift and Objective-C
whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

do2day

Do2Day

  • #about
  • #myapps
  • #contact
  • #privacy
  • #Advertise
  • #myQuestions

Android Database Interview IOS IOSQuestions Javascript Objective-c Programming Swift Tips&Tricks Web Wordpress

  • Exploring Single Point Failures: Causes and Impacts
  • Exploring the Pros and Cons of Primitive Data Types
  • Essential Coding Standards and Best Practices for Clean Code
MyCodeTips

©mycodetips.com

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.