ekim420
ekim420

Reputation: 465

Bolding a word inside innerText

I am trying to bold a few words inside a paragraph. So far I tried using HTML tags before realizing that doesn't work. Is there a way to do this without getting the element?

var text2_2 = document.createElement("p");
text2_2.className = "reasoning";
text2_2.innerText = "All vitamins are <strong>required</strong> by our ..."

Upvotes: 1

Views: 4934

Answers (1)

Mamun
Mamun

Reputation: 68933

Since the string contains some HTML in it and to get the effect of that use innerHTML instead of innerText.

var text2_2 = document.createElement("p");
text2_2.className = "reasoning";
text2_2.innerHTML = "All vitamins are <strong>required</strong> by our ..."

document.body.appendChild(text2_2);

Upvotes: 5

Related Questions