Home  >  Article  >  Web Front-end  >  How to make bold in javascript

How to make bold in javascript

藏色散人
藏色散人Original
2021-10-14 15:40:419494browse

How to implement bolding in JavaScript: 1. Use the p tag to create a line of text; 2. Obtain the input object by specifying the id; 3. Use the button tag to create a button; 4. Implement the text bolding by executing the addbold function That’s it.

How to make bold in javascript

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to bold in javascript?

js control text bolding:

Create a new html file and name it test. html, used to explain how to control text bolding in js.

How to make bold in javascript

In the test.html file, use the p tag to create a line of text with the content "This is the text of the test".

How to make bold in javascript

In the test.html file, set the id of the p tag to myid, which is mainly used to obtain the input object through this id below.

How to make bold in javascript

In the test.html file, use the button tag to create a button with the button name "Text Bold".

How to make bold in javascript

In the test.html file, bind the onclick event to the button button. When the button is clicked, execute the addbold() function.

How to make bold in javascript

In the js tag, create the addbold() function. Within the function, use the getElementById() method to obtain the p tag object through id (myid) and set its style. The fontWeight attribute value is bolder, thereby making the text bold.

How to make bold in javascript

Open the test.html file in the browser and click the button to see the effect.

How to make bold in javascript

Recommended study: "javascript basic tutorial"

The above is the detailed content of How to make bold in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn