Contents
You can make text bold in Javascript by using the font-weight property. This property allows you to set the thickness of the lines making up the characters.
Checkout this video:
Introduction
In this guide, we will show you how to make text bold in Javascript. There are two ways to do this: using the tag or using the font-weight property in CSS. Let’s take a look at both methods.
Basic Syntax
Bold text is often used to emphasize a point or draw attention to a particular section of text. In HTML, you can create bold text using the tag. In JavaScript, you can use the document.write() method to write bold text to a web page.
Here is a simple example of how to create bold text using the tag:
This text is bold
And here is an example of how to create bold text using the document.write() method:
document.write(“This text is bold“);
The document.write() Method
The document.write() method is used to write text to a document. The text appears in the browser window, just as if it had been typed into the HTML file.
The write() method can be used to write an HTML tag:
document.write(“This text is bold.“);
Result: This text is bold.
The innerHTML Property
In order to make text bold in JavaScript, you can use the innerHTML property. This property can be used to get or set the HTML content of an element. To set the boldness of text, you can set the innerHTML property to a string containing the tag. For example:
“`
element.innerHTML = “This is bold text“;
“`
You can also use the style property to set the font-weight of an element to “bold”. For example:
“`
element.style.fontWeight = “bold”;
“`
The style Property
You can make text bold in JavaScript using the style property. This property is used to set the inline style of an element. The inline style is specified as a CSS stylesheet. To make text bold, you need to set the font-weight property to bold.
Example
This example makes the text bold:
“`javascript
document.getElementById(“demo”).style.fontWeight = “bold”;
“`
The fontWeight Property
The fontWeight property is used to set the boldness of a font. The following values are valid:
– normal
– bold
– bolder
– lighter
– 100, 200, 300, 400, 500, 600, 700, 800, 900
The tagName Property
The easiest way to make text bold in Javascript is to use the tagName property. This will return the name of the element, which can be used to make a decision about whether or not the element is bold. For instance, if you have a
Conclusion
There you have it! That’s how you can make text bold in JavaScript. As you can see, it’s a fairly simple process. However, if you want to take your skills to the next level, we suggest checking out our other tutorials on JavaScript.