Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery $('id').text with Bold

I have a jquery that changes the text of a link like so:

if (urlfind > 0) {
    $('#linkurl').text('More info');
}

And html:

<a href = "" id = "linkurl"></a>

I am trying to add bold to this link, but adding <b>More Info</b> leaves them escaped in the text itself, rather than making the text bold

like image 539
user3057706 Avatar asked Feb 23 '26 17:02

user3057706


1 Answers

.html() sets string as HTML content, whereas .text() sets the string as text.

Write:

if (urlfind > 0) {
    $('#linkurl').html('<b>More info</b>');
}

OR

if (urlfind > 0) {
    $('#linkurl').html('<strong>More info</strong>');
}

.html() .text()

like image 96
codingrose Avatar answered Feb 25 '26 08:02

codingrose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!