Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:53:38+00:00 2026-06-12T13:53:38+00:00

I have a place where I am trying to show code in a text

  • 0

I have a place where I am trying to show code in a text area. I have dumbed down the example but basically user can input some fields, click a button, and the code snippet displays in a text area below for them to edit if they want and then copy.

I finally got it working to display the actual code snippet. But now I can’t seem to find a way to format it so that it is indented and looks nice.

var mySnippet =
"<div id=\"myOuterDiv\">"
    + "<div id=\"myInnerDiv\">"
    + "</div>"
    + "</div>";
$('#mySnippetArea').text(mySnippet);

Which displays in my text area like so.

<div id="myOuterDiv"><div id="myInnerDiv"></div></div>

Where as I would like to see it as:

    <div id="myOuterDiv">
        <div id="myInnerDiv">
        </div>
    </div>

I’d really like to avoid any 3rd party plugins as its for work an a pain to get approval. It’s just 4 small snippets I need to format.

UPDATE
This appears to work as I need.

var mySnippet =
        "<div id=\"myOuterDiv\">\r"
            + "    <div id=\"myInnerDiv\">\r"
            + "    </div>\r"
            + "</div>\r";

Output:

<div id="myOuterDiv">
    <div id="myInnerDiv">
    </div>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:53:39+00:00Added an answer on June 12, 2026 at 1:53 pm

    Add a \n if you want a new line like

    var mySnippet = "<div id=\"myOuterDiv\">\n"
        + "<div id=\"myInnerDiv\">\n"
        + "</div>\n"
        + "</div>\n";
    $('#mySnippetArea').text(eventSnippet);
    

    Single character escape sequences:

    \b: backspace (U+0008 BACKSPACE)
    \f: form feed (U+000C FORM FEED)
    \n: line feed (U+000A LINE FEED)
    \r: carriage return (U+000D CARRIAGE RETURN)
    \t: horizontal tab (U+0009 CHARACTER TABULATION)
    \v: vertical tab (U+000B LINE TABULATION)
    \0: null character (U+0000 NULL)
    

    Example: http://jsfiddle.net/jtx7e/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to place a Loading Animation onto my page but have never
In Android, I'm trying trying to have the user enter a place they name,
I'm trying to place a button. I have its position set to absolute, so
I'm trying to place a flash video (object, swf) inside a div, and have
Greetings, I have problem with errorPlacement, I'm trying to place the error message next
I have a layered application. I am trying to determine where to place a
I have this js code where I am using the Mapstraction library to show
I am trying to find a date picker that can show dates to select
I'm trying to protect page by making a member only area the code I
basicly, I'm trying to show the result of a listview (created with QSLite)but in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.