admin管理员组

文章数量:1022769

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 not innerText – 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
Add a ment  | 

1 Answer 1

Reset to default 5

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);

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 not innerText – 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
Add a ment  | 

1 Answer 1

Reset to default 5

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);

本文标签: javascriptBolding a word inside innerTextStack Overflow