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

150
Views
How to change the font of paragraph text when using document.getElementById("").innerHTML?

I am building a transcript based off user input and I was wondering if anyone could point me in the right direction of how I might be able to change the font-style of the strings stored in text_to_add_one and text_to_add_two.

if (build_transcript) {
    var text_to_add_one = "<b>" + "YOU: " + "</b>" + `${transcript_you}`;
    var text_to_add_two = "<b>" + "COMPUTER: " + "</b>" + `${transcript_computer}`; 
    document.getElementById("wordsIncluded").innerHTML += "<p>" + text_to_add_one + "</p>" + "<p>"+ text_to_add_two + "</p>" + "</br>";
   build_transcript = false;
}

//wordsIncluded is a div

I have tried the approach below but it doesn't seem to work!

 document.getElementById("wordsIncluded").innerHTML += "<p id="changeFont">" + text_to_add_one + "</p>" + "<p id="changeFont">" + text_to_add_two + "</p>" + "</br>";

CSS FILE

#changeFont {
      font-style: 'Quicksand';
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You should not use "<p id="changecolor">". As the code coloring shows, it does not matter part of the string. You should use "<p id=\"changecolor\">" or '<p id="changecolor">'

about 4 years ago · Juan Pablo Isaza Report

0

you need to use single quotes .

document.getElementById("wordsIncluded").innerHTML += '<p id="changeFont">' + text_to_add_one + '</p>' + '<p id="changeFont">' + text_to_add_two + '</p>' + '</br>';
about 4 years ago · Juan Pablo Isaza Report

0

Try some thing like below.

const transcript_you = "me";
const transcript_computer = "mac";

var text_to_add_one = `<b>YOU: </b>${transcript_you}`;
var text_to_add_two = `<b>COMPUTER: </b>${transcript_computer}`;

document.getElementById(
  "wordsIncluded"
).innerHTML += `<p class="changeFont">${text_to_add_one}</p><p class="changeFont">${text_to_add_two}</p></br>`;
p.changeFont {
  color: red;
}
<div id="wordsIncluded"></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!