Skip to content Skip to sidebar Skip to footer

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: I am

Solution 1:

.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()

Solution 2:

Or if you wanted to get extravagant (and somewhat unnecessary):

if (urlfind > 0) {
  $('#linkurl').css('font-weight', 'bold');
}

Solution 3:

The text() method inserts text, while the html() method inserts HTML, and <b> tags are HTML

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

Solution 4:

You can keep your .text() method by simply adding the style via the .css() method:

if (urlfind > 0) 
{
    $('#linkurl')
        .text('More info')
        .css('font-weight', 'bold');
}

See working jsFiddle demo

Post a Comment for "Jquery $('id').text With Bold"