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

187
Views
How to achieve multi-line output with formatting in JavaScript

I am experimenting with the following codepen.io trinket and trying to achieve multiline output with formatting for the JavaScript text that is returned in response to user-input.

For instance, if the user types "/engage" the following text is returned:

"Follow the white rabbit. I want this to be the second line"

The code is below. I would like the above text to:

a) be output on two separate lines with my being able to control the breaks between lines (like br in HTML) b) allow some basic formatting - specifically to add bold formatting to the word "rabbit". c) allow for changing the font size of "follow" to a larger font/or different style etc.

In short, I want to be able to add formatting (hyperlinks are also a key one) and can't find any direct documentation on this for useful reference. the \n works for line breaks, thank you @epascarello

I have tried various things but they all come up with errors.

RELEVANT CODE

submitForm.addEventListener("submit", function(e) {
    e.preventDefault();
    if (input.value === "/clear") {
        clearCommand();
    } else if (input.value === "/list" || input.value === "help") {
        listAllCommands();
    } else if (input.value === "/connect") {
        goProgress();
    } else if (input.value === "/engage") {
        matrixEffect();
        clearCommand();
        textArea.value = "Follow the white rabbit. I want this to be the second line"
    } else {
        textArea.value +=
            "\nERROR: Unknown command! Type 'help' for list of commands.";
        input.value = "";
    }
    textArea.scrollTop = textArea.scrollHeight;
});

CODEPEN ENTIRE SNIPPET

https://codepen.io/damyco/pen/oyewjR

about 4 years ago · Juan Pablo Isaza
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!