0

I'm currently having a problem replacing the current text with the same text but in bold. I've tried the following

var valueInRow = $(value).closest(".label.imaged").text();
var result = valueInRow.bold();
$(value).closest(".label.imaged").text().replaceWith(result);

But I'm not sure why it doesn't work; Any ideas?

Sainan
  • 1,274
  • 2
  • 19
  • 32
Raziel
  • 1,448
  • 2
  • 17
  • 35

3 Answers3

3

You can clearly use .wrapInner():

Wrap an HTML structure around the content of each element in the set of matched elements.

$(value).closest(".label.imaged").wrapInner("<strong />");
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
3

Use .css() method also

var valueInRow= $(value).closest(".label.imaged");
valueInRow.css('font-weight', 'bold');
Sudharsan S
  • 15,336
  • 3
  • 31
  • 49
1

The existing answers are entirely valid, but I'll add this an alternative that doesn't add any new HTML elements or inline styles.

Creating a CSS rule that's purpose is simply to bold text, such as:

.boldText{ font-weight: bold !important; }

Will then allow you to bold any element simply by adding that class:

$(value).closest(".label.imaged").addClass("boldText");

*Note about the use of !important: This is usually not recommended CSS as it's often used in the wrong way. However in this case if you add a class called boldText to an element, chances are, you will always want it to have bold text.

DBS
  • 9,110
  • 4
  • 35
  • 53