1

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 ..." 
2
  • 5
    Use innerHTML not innerText Commented Feb 16, 2018 at 2:51
  • 2
    @j08691 what a simple solution. Thank you very much. Commented Feb 16, 2018 at 2:52

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I was unaware of innerHTML. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.