admin管理员组文章数量:1392897
I'm trying to make text (fat) bold. Curretly I managed to do this whit code below:
Movie <b>fat</b> was been added
But this bold tags won't work. Now the question is how to enable html for only (fat), to be bold like this: Movie
fat was been added
My code so far:
var boldy = (Movie[0].title)
var fat = boldy.bold()
$("div.container div:first").text("Movie " + (fat) + " was been added")
I also tried whit this:
$("div.container div:first").html("Hello <b>"+(boldy)+"</b>")
I'm trying to make text (fat) bold. Curretly I managed to do this whit code below:
Movie <b>fat</b> was been added
But this bold tags won't work. Now the question is how to enable html for only (fat), to be bold like this: Movie
fat was been added
My code so far:
var boldy = (Movie[0].title)
var fat = boldy.bold()
$("div.container div:first").text("Movie " + (fat) + " was been added")
I also tried whit this:
$("div.container div:first").html("Hello <b>"+(boldy)+"</b>")
Share
Improve this question
asked Jun 3, 2017 at 22:31
SlasherSlasher
61810 silver badges32 bronze badges
5
-
The second example
.html(...)
works. IsMovie[0].title
defined / empty string? – le_m Commented Jun 3, 2017 at 22:33 - Second example returns empty string, yes and nothing happens. – Slasher Commented Jun 3, 2017 at 22:34
-
so... is
Movie[0].title
empty? What doesconsole.log(boldy);
print? – le_m Commented Jun 3, 2017 at 22:36 - My first example applys <b> like it should. But html inside .text() is not working. – Slasher Commented Jun 3, 2017 at 22:37
-
1
@Shasher It's not a bug, it's a feature -
.text()
does not render HTML - that's why you have.html()
. – le_m Commented Jun 3, 2017 at 22:38
4 Answers
Reset to default 4
var word ="fat"
$("div:first").html("Movie <b>"+word+"</b> was been added")
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>
You can use the following:
$("div.container div:first").css("font-weight","Bold");
That will change the property font-weight from that div to bold.
@EDIT: You can make a div with an ID and set that ID on the jQuery mention:
$("div.container div:first div#text").css("font-weight","Bold");
var world = 'world';
$("div").html(`Hello <b>${world}</b>`);
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
Movie fat was been added
</div>
var html = $("div.container div:first").html;
$("div.container div:first").html(html.replace(/fat/gi, '<strong>$& </strong>'));
本文标签: javascriptMake bold text inside element (jQuery)Stack Overflow
版权声明:本文标题:javascript - Make bold text inside element (jQuery) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744592496a2614578.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论