Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
How do i bold a text in JavaScript?

I am trying to change text to bold, which is really hard. I tried many times using various ways, for example:

//1: 

document.getElementById('boldtext').innerHTML = "<b>" += document.getElementById('boldtext').innerHTML += "</b>"; //which dosent work

//2:

document.getElementById('boldtext').bold(); //dosent work too


Any ideas on how to bold text in Javascript?

//My code so far:
The whole code is this: function getSelectionText() { var text = ""; if (window.getSelection) { text = window.getSelection().toString(); } else if (document.selection && document.selection.type != "Control") { text = document.selection.createRange().text; } alert(text); }; let BoldButton = document.createElement('input'); /*boldbuttonlol*/ BoldButton.type = 'button'; BoldButton.value = 'bold highlighted text'; BoldButton.onclick = () => { getSelectionText(); }; document.body.appendChild(BoldButton); 

Thank you!!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

simply use

document.getElementById('boldtext').style.fontWeight = "bold";
about 4 years ago · Juan Pablo Isaza Report

0

Please try this

function makeMeBold() {
        document.getElementById('boldtext').style.fontWeight = "bold";
   }
<input id="makeBold" type="button" onclick="makeMeBold()" value="Click me"/>
<div id="boldtext">Sample text to make bold</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!