JavaScript bold method
The lastIndexOf method returns a bold string defined using the HTML b tag. The syntax is as follows:
The code copy is as follows:
str_object.bold()
Tip: This method does not comply with ECMA standards and is not recommended for use.
bold method example
The code copy is as follows:
<script language="JavaScript">
var str = "www.VeVB.COM";
document.write(str.bold());
</script>
Run this example and output:
The code copy is as follows:
www.VeVB.COM
Tip: This method returns a bold string defined using HTML b tag, that is, using this method cannot dynamically change the font of the page element to bold. If you want to dynamically change the element font to bold, you can refer to the following example:
Further reading: Change the font size of page elements
The code copy is as follows:
<html>
<script language="JavaScript">
function changFont( x ){
var font_style = x;
var article = document.getElementById("article");
if( typeof font_style == "string" ){
article.style.fontWeight = font_style;
} else {
article.style.fontSize = font_style;
}
}
</script>
<body>
<p>
<a onClick="changFont('normal');">Normal</a> <a onClick="changFont('bold');">Bold</a>
<a onClick="changFont(14);">Small</a> <a onClick="changFont(18);">Large</a>
</p>
<p id="article">
I'm some text...<br />
Some Text ...
</p>
</body>
</html>
In this example, the way the font CSS style is controlled through JavaScript, the display font (id="article") can be switched in real time between bold, normal, small, and large fonts.