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

229
Views
Storing HTML in a JS variable but preserving the HTML variables

Im trying to save some HTML in a JS variable by using the backtick formatting however is it possible to preserve the HTML variable according to the following example

var msg = "This is a test" + "\n" + "Test"

Im attempting to store this variable as a HTML paragraph while keeping the linebreaks

var emsg = '<p style="white-space: pre-wrap;"><\"{msg}"\</p>'

But when sending that content in an email to myself (Using Emailjs) I get the following

<"{msg}"

Any clue what I'm doing wrong? Thanks!

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

0

  1. You are using single quotes ('), not backticks (`)

  2. Placeholders in template literals are indicated by a dollar sign ($), which you are missing.

var msg = "This is a test" + "\n" + "Test"

var emsg = `<p style="white-space: pre-wrap;"><\"${msg}"\</p>`

console.log(emsg)

about 4 years ago · Juan Pablo Isaza Report

0

You could go with template literals like @spectric showed. or you can go with simple quote using + to seperate it with msg variable

var msg = "This is a test" + "\n" + "Test";//    V     V
var emsg = '<p style="white-space: pre-wrap;"><\"'+msg+'"\</p>';
console.log(emsg);
about 4 years ago · Juan Pablo Isaza Report

0

as described + removing the extra <\" and "\ probably

var emsg = <p style="white-space: pre-wrap;">${msg}</p>

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!