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 8170381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:07:10+00:00 2026-06-06T21:07:10+00:00

Adding long text inside an HTML element such as a DIV, the element wraps

  • 0

Adding long text inside an HTML element such as a DIV, the element wraps that text. Exactly like this Question text, actually.
How can I take the text from such an HTML element and determine where it breaks? i.e. where a new line is inserted.

For instance, in this box, there’s a new line after “…like this”, one after “…where it” and two after “…is inserted.”

  • 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-06T21:07:11+00:00Added an answer on June 6, 2026 at 9:07 pm

    So, the problem is actually how to do word-wrapping in HTML5 canvas:

    This is all for converting some standard HTML elements which hold text
    and/or a photo into an HTML5 canvas. And unfortunately, the
    ‘.fillText()’ method is not smart enough to break a piece of text for
    me, so I need to “manually” detect each line.

    What you might do is measureText subsequently adding one word at a time. Measure the first word, and if it fits to the width of your container (ctx2d.measureText(words).width <= containerWidth), then you can add another word and measure again. Until the string of words doesn’t fit. If it doesn’t – you have to fillText on the next line.

    As for the manually inserted line breaks, they are specifically represented in HTML, either by \n or \r characters in textareas or by HTML elements, like <br \>. Thus, before measuring the text you might want to split it by paragraphs.

    In textareas:

    var paragraphs = textarea.value.split('\n');
    

    In non-form elements:

    var paragraphs = [];
    
    // getting all <p> and elements in a typical HTML element
    // as well as individual text nodes (they are just DOM-nodes),
    // separated by <br /> elements
    var innerNodes = nonFormElement.childNodes;
    
    for (var i = 0, len = innerNodes.length; i += 1) {
        // if a sub-element has some text in it,
        // add the text to our list
        var content = innerNodes[i].textContent;
        if (content) {
            paragraphs.push(content);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

iam adding a contact to the device using this code long Contact_Id = 100;
I have a video that is 60 seconds long. I am working on adding
I have a text field entry in my view that I would like to
I am adding a textfield to my view like this: UITextField* tf_email = [[UITextField
I know this is a long shot, but I have a huge text file
I have javascript function that automatically adds input fields together, but adding numbers like
I have a UIAlertView with a very long text that I put in the
Long story, long: I am adding a web interface (ASPX.NET: VB) to a data
I have a div that contains a paragraph, a list and a right-floated div.
I have an input field, in which a user will enter text inside. When

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.