Reputation: 3680
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?
Upvotes: 9
Views: 67067
Reputation: 959
Toggle/add a css class on the containing element (TextBox).
document.getElementById('TextBox').className = 'bold';
.bold {
font-weight: bold;
}
<div id='TextBox'>
My text.
</div>
Or something like that.
Upvotes: 2
Reputation: 4987
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.
Upvotes: 19