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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:16:56+00:00 2026-06-04T02:16:56+00:00

I have a div with contenteditable=true set in order to allow inline editing (for

  • 0

I have a div with contenteditable=true set in order to allow inline editing (for RTE purposes).

Im aware different browsers handle the enter keypress differently, FF inserts <br> and IE inserts <p>

The issue I am experiencing is when entering text across various lines.

e.g for the text:

line 1
line 2

line 3


line 4

In FF, when entering the above then switching contenteditable=false, the line formatting remains as expected.

However, when editing in IE with multiple lines of text, then setting contenteditable=false, any blank lines are collapsed. e.g:

line 1
line 2   
line 3    
line 4

If I then reset contenteditable=true, these collapsed lines are restored.

I am guessing it has something to do with the use of <p> by IE, any ideas how I can prevent the lines from being collapsed when contenteditable=false?

  • 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-04T02:16:57+00:00Added an answer on June 4, 2026 at 2:16 am

    You could try to walk around this IE-behavior by catching ENTER, and adding BR instead of <P>&nbsp;</P>.

    pad.addEventListener('keydown',keyDown,false);
    
    function keyDown(e){
        if(e.keyCode!=13) return;
        pad.innerHTML+='<br />\b';
        e.stopPropagation();
        e.preventDefault();
        return false;
    }
    
    <div id="pad" contenteditable="true"></div>
    

    The trick is to add “\b” (backspace) to the end of the line, otherwise IE won’t make newline before user hits another key. However, these backspaces are causing troubles when using innerHTML later. To remove backspaces, you just replace them with "" with RegExp:

    padsInnerHTML=pad.innerHTML.replace(/LITERAL_BACKSPACE_CHARACTER/g,'');
    

    In the regexp you’ll need a literal backspace character, /\b/ won’t work. To actually see the backspace character, you can run your code in Opera with this keyDown(), write some letters and hit ENTER in pad and copy-paste the character to your code.

    Notice, that this code should run in IE only, other browsers will mess up with newlines.


    Why is this working, I don’t know. It seems, that IE adds some none-printing character after <BR />, which has to be removed to create an instant newline after pressing ENTER.

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

Sidebar

Related Questions

I have a div element with contenteditable set to true, and I want to
i have a div with contenteditable=true that im using in place of textarea using
I have a div with contexteditable set to true and with a special google
I have a div with contenteditable set. This div contains an inner div like
I have a snippet of Javascript code as follows: <div id=TestControl contentEditable=true style=width:200px; position:absolute;
So I have a contenteditable=true div, of which there are images and text within
I have contenteditable div element. I want to set a watermark for it so
I have a contenteditable div, like so: <div id=test contentEditable=true style=width: 600px; height:300px;>Lorem ipsum
Currently I am making an editor using contenteditable. I have the following: <div contenteditable=true>
I have a <div contenteditable=true> that I am trying to use to get text

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.