0
  var text1 = "Mind";
  var text2 = document.getElementById("t1").value;
  var text3 = text1.concat(text2);
  document.getElementById("t2").innerHTML = text3;

I want to make the text of variable "text2" in bold when displayed, Please tell how I can do that...

  • You can wrap `text2` in an HTML element and apply bold css to it. – Hassan Imam Feb 03 '22 at 05:13
  • Consider adding `font-weight: bold` to the element's style. See also: [Bold text in the from field: ?](https://stackoverflow.com/questions/5323508/bold-text-in-the-from-field-input) – Wyck Feb 03 '22 at 05:36

3 Answers3

0

text2.style.fontWeight = 'bold';

Martin King
  • 37
  • 1
  • 6
0

Here you do not need any css. Bold function Create a tag .

var text1 = "Mind";
var text2 = document.getElementById("t1").value.bold();
var text3 = text1.concat(text2);
document.getElementById("t2").innerHTML = text3;

Or You can do this

var text1 = "Mind";
var text2 = document.getElementById("t1").value;
document.getElementById("t1").style.fontWeight = "900";
var text3 = text1.concat(text2);
document.getElementById("t2").innerHTML = text3;
  • Actually, t1 is an input (type: text), that is it is a text box. So the code you mentioned isn't working.... – MOUSHAM PATRA Feb 03 '22 at 05:27
  • For what it's worth, MDN says [`bold()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/bold) is "Deprecated: This feature is no longer recommended." But I think `style.fontWeight` should still work for an input element. [Demo](https://jsfiddle.net/6satr1fw/) – showdev Feb 03 '22 at 05:35
0

In two ways

1.add its style like this:

text2.style.fontWeight = 'bold';
  1. you can do it setting the innerHTML property of the element, just like this:

     text2.innerHTML = "<b>Hello</b>";
    
Lakshmanan k
  • 122
  • 7
  • Sorry, not working... – MOUSHAM PATRA Feb 03 '22 at 05:33
  • True, `` will not work with an `` because [you can not place any other element within an input element](https://stackoverflow.com/a/19236837/924299). But `style.fontWeight` [works](https://jsfiddle.net/6satr1fw/). – showdev Feb 03 '22 at 05:43