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 ..."
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 ..."
Share
Improve this question
edited Feb 16, 2018 at 2:50
ekim420
asked Feb 16, 2018 at 2:47
ekim420ekim420
4652 gold badges6 silver badges21 bronze badges
2
-
5
Use
innerHTML
notinnerText
– j08691 Commented Feb 16, 2018 at 2:51 - 2 @j08691 what a simple solution. Thank you very much. – ekim420 Commented Feb 16, 2018 at 2:52
1 Answer
Reset to default 5Since 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);