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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:21:38+00:00 2026-05-21T10:21:38+00:00

Firefox inserts a <br /> tag on press enter whereas the other browsers are

  • 0

Firefox inserts a <br /> tag on press enter whereas the other browsers are adding either a <p> or <div>. I know that chrome and safari are inserting the same tag of the firstchild of the contentEditable div. So do Firefox, however, if the first tag’s innerHTML is empty firefox is just ignoring the tag and creating a new line by pushing the default node in the second line and writes directly inside the editor instead of inside a child node. So basically, I want Firefox to write inside the given tag and continue to insert that kind of node on each press on enter. How can it be done? Any suggestions?

  • 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-05-21T10:21:38+00:00Added an answer on May 21, 2026 at 10:21 am

    I’ve found the solution 🙂 In order to make this work, you’ve to give an id to the caret’s parent element. Then you can use the following code. Please note that I get the browsernName from c# and put it into a hidden field. That’s why I equaled it to “firefox”. The following code is tested with FF 3.6 and it works perfectly. The only thing is that you’ll have to check the caret’s parent element and if it is not equal to the current row’s id, then you’ll have to place the caret inside the current row by using a selection function. Also, perform this code on the keyup event and make sure that if you perform some other codes on the keyup event, put this code at the end of it! Anways, enjoy 🙂

    // The code works good in the following cases:
    // 1) If there is text inside the editor and the user selects the whole text
    //    and replace it with a single character, the <p> tag will be placed and the
    //    text will place inside the p tag
    // 2) If the user selects the whole code and deletes it and begins to type again
    // 3) If the user types normally and press enter 
    // NB: Please note me if you find any bug
    
    if (browserName == "firefox") {
        //remove all br tags
        var brs = txteditor.getElementsByTagName("br");
        for (var i = 0; i < brs.length; i++) { brs[i].parentNode.removeChild(brs[i]); }
        //check whether there is a p tag inside
        var para = txteditor.getElementsByTagName("p");
        if (para.length == 0) {
            var inner = txteditor.innerHTML.replace(/^\s+|\s+$/g, '');
            var str = (inner == "") ? "&#8203;" : txteditor.innerHTML;
            var nText = "<p id=\"" + cRow + "\">" + str + "</p>";
            // in order to prevent a dublicate row clear inside the text editor
            txteditor.innerHTML = "";
            document.execCommand('insertHTML', false, nText);
        } else {
            // always make sure that the current row's innerHTML is never empty
            if (document.getElementById(cRow).innerHTML == "")
                document.getElementById(cRow).innerHTML = "&#8203;";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.