JavaScript italics method entry instance (displays string in italics)
- 2020-03-30 04:08:58
- OfStack
JavaScript italics method
The italics method returns the (italic) string defined using the HTML I tag attribute. The syntax is as follows:
str_object.italics()
Note: this method does not conform to ECMA standards and is not recommended.
Instance of italics method
<script language="JavaScript">
var str = "www.jb51.net";
document.write( str.italics() );
</script>
Run the example and output:
www.jb51.net
Tip: this method returns a string defined using the HTML I tag, even if it does not dynamically change the font to italics. If you want to change the element font to italics dynamically, see the following example:
Extended reading: change the font of page elements to italics
<html>
<script language="JavaScript">
function changFont( x ){
document.getElementById("article").style.fontStyle = x;
}
</script>
<body>
<p>
<a onClick="changFont('normal');"> normal </a> <a onClick="changFont('italic');"> italics </a>
</p>
<p id="article">
I am some words ...<br />
Some Text ...
</p>
</body>
</html>
In this example, you can dynamically change the font (id="article") to italics by using JavaScript to control the font CSS font-style style.