Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add bold text using javascript

I'm trying to add bold text to my website using javascript, but it literly shows the "<b>". How do i fix this?

var TextBox = document.getElementById("TextBox");

TextData.textContent = "<b> hello </b>"

I tried using the document.write(""); , but it changes the whole website. Any Suggestions?

like image 640
nachshon f Avatar asked May 07 '26 19:05

nachshon f


1 Answers

You can add first the content to textbox like this:

TextBox.innerHTML = "Hello";

then add its style like this:

TextBox.style.fontWeight = 'bold';

Or you can do it setting the innerHTML property of the element, just like this:

 TextBox.innerHTML = "<b>Hello</b>";

I tend to set style separately. You should avoid adding style like this, better use css classes.

like image 67
Kristijan Iliev Avatar answered May 10 '26 10:05

Kristijan Iliev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!