In CSS we can use text-transform to change the text to uppercase, lowercase or to capitalized letters.
The textTransform
property sets or gets the capitalization of a text
in Javascript.
textTransform |
Yes | Yes | Yes | Yes | Yes |
Return the textTransform property:
var v = object.style.textTransform
Set the textTransform property:
object.style.textTransform='none|capitalize|uppercase|lowercase|initial|inherit'
Value | Description |
---|---|
none | No transform. Default |
capitalize | uppercase the first letter of each word |
uppercase | uppercase all letters |
lowercase | lowercase all letters |
initial | Set to default value. |
inherit | Inherit from parent element. |
Default Value: | none |
---|---|
Return Value: | A string representing the text transformation |
CSS Version | CSS1 |
The following code shows how to capitalize text.
<!DOCTYPE html>
<html>
<body>
<p id="myP">This is an example paragraph.</p>
<button type="button" onclick="myFunction()">test</button>
<script>
function myFunction() {<!-- ww w . j a va 2 s .co m-->
document.getElementById("myP").style.textTransform = "capitalize";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to uppercase all letters.
<!DOCTYPE html>
<html>
<body>
<p id="myP">This is an example paragraph.</p>
<button type="button" onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from ww w . j ava 2 s . com-->
document.getElementById("myP").style.textTransform = "uppercase";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the text transformation settings.
<!DOCTYPE html>
<html>
<body>
<!-- w w w . j a v a2 s . com-->
<p id="myP" style="text-transform:lowercase;">ASDF This Is An Example.</p>
<button type="button" onclick="myFunction()">test</button>
<script>
function myFunction() {
console.log(document.getElementById("myP").style.textTransform);
}
</script>
</body>
</html>
The code above is rendered as follows: