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
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);
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);
本文标签: javascriptBolding a word inside innerTextStack Overflow
版权声明:本文标题:javascript - Bolding a word inside innerText - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745513214a2153920.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论