Home >Web Front-end >Front-end Q&A >How to make bold in javascript
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.
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.
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".
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.
In the test.html file, use the button tag to create a button with the button name "Text Bold".
In the test.html file, bind the onclick event to the button button. When the button is clicked, execute the addbold() function.
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.
Open the test.html file in the browser and click the button to see the effect.
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!