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

  • SEARCH
  • Home
  • 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 8375417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:10:20+00:00 2026-06-09T15:10:20+00:00

Getting an element of the DOM like this $(‘#id’).content().text(); Problem arises with If it

  • 0

Getting an element of the DOM like this

$('#id').content().text();

Problem arises with

If it gets this:

<p>Hello</p>
<p><br></p>
<p>World</p>

Naturally in Html looks like:

Hello 

World

But this jquery .text() method returns: HelloWorld

How to interpret <br> as new line? <-> How to get the text exactly as I see it in HTML?

.html() gives all the HTML tags, which I don’t want. I just need the plain text with spaces, if possible.

  • 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-09T15:10:22+00:00Added an answer on June 9, 2026 at 3:10 pm

    .text() is plain text without formatting. It is literally the concatenation of the text nodes without any other HTML codes (including new lines which are represented by <br> or <p> tags, not by newlines).

    .html() is the exact HTML of a container tag.

    If you use this, it will get you an approximation of your text with new lines:

    var item = document.getElementById("id");
    var text = item.innerText || item.textContent;
    

    It’s looking at both .textContent and .innerText due to browser compatibility issues.

    See http://jsfiddle.net/jfriend00/Xs5P3/ for a working demo.

    A Google search for “HTML to text conversion” gives a lot of options to investigate.

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

Sidebar

Related Questions

I am getting an array with a single element in it, [http://i.foobar.com/This-Is-The-Remainder-Of-The-Link.jpg] and I'm
I have an xml structure like this <element> <foodjoint_name>DineOut</foodjoint_name> <logo>http://192.168.1.112/dineout/images/dominos.jpg</logo> </element> I am parsing
i wanna do something like Document dom = new Document(); Element ele = new
Possible Duplicate: Getting jQuery-inserted DOM elements without requerying for element after insertion Is there
If I have a string of HTML, maybe like this... <h2>Header</h2><p>all the <span class=bright>content</span>
Possible Duplicate: Getting the ID of the element that fired an event using JQuery
I'm getting a nonsensical error message: The element type manifest must be terminaed by
I am not getting that how to differentiate same element name for eg City,Area
I am having issues getting my JQuery Selector to access a particular HTML element.
I'm getting some problems with vertical aligment. I want to put my <span>›</span> element

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.