We can format text in JavaScript using the following methods:
- bold () – makes text bold
- italics () – italicizes text
- fontcolor () – changes the color of the text to the specified color as an argument.
- fontsize () – changes the size of the text to the specified size as an argument.
- toLowerCase () – changes text to all lowercase letters.
- toUpperCase () – changes text to all upper case letters.
For example;
We create a variable greeting and format it accordingly:
<script language=”javascript”>
Var greeting=”Welcome to JavaScript Tutorial”
greeting=greeting.fontcolor(“red”);
greeting=greeting.bold();
greeting=greeting.fontsize(“10”);
greeting=greeting.italics();
document.write(greeting);
</script>
The Output