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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:56:52+00:00 2026-05-17T14:56:52+00:00

I am making a WYSIWYG editor, what I want to do is preventDefault on

  • 0

I am making a WYSIWYG editor, what I want to do is preventDefault on the enter key, and instead, when enter is pressed, it creates a new line, with tags <div></div>. So essentially each <div> is one line. I don’t know how to create the <div> and have the pointer start between each <div> like this:

<div>Line one here</div> // Press enter
<div>Start typing next line here</div> // When you press Enter, it creates a div and automatically when you start typing its in between the tags.

Then after you press a new line again, it just creates another <div> for the next line… Can anyone help? I don’t need help with the preventDefault, just the new action to be taken if Enter is pressed.

  • 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-17T14:56:53+00:00Added an answer on May 17, 2026 at 2:56 pm

    On the face of it, this shouldn’t be too difficult. However, browser inconsistencies make it problematic.

    The basic approach is:

    1. Capture the Enter keypress and prevent the browser default behaviour. Easy so far.
    2. Use a DOM Range in most browsers or TextRange in IE to get the current caret location from the browser’s selection object. Slightly fiddly in IE.
    3. Create a new <div> if the caret is at the end of the current <div> or split the current <div> if not. This is not trivial (think of what you need to do if, say, the caret was inside nested inline elements within the <div>) but still doable.
    4. Once again using a Range or TextRange, place the caret at the start of the new <div>. This is where it starts to go wrong: WebKit won’t let you place the caret at the start of a text node, and IE has its own problems with this, the details of which I’ve now forgotten.

    It’s hard. Look at what the big editors (TinyMCE, CKEditor) do to handle this.

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

Sidebar

Related Questions

I am making a WYSIWYG editor from scratch using execCommand(). I want to disable
I am making a WYSIWYG webpage editor: http://brokenmyriad.com/editor2.php , however I have come across
I'm making a WYSIWYG editor, and I need to know how to get caret
I'm making a new game, and I want to use my own textures for
When making a simple WYSIWYG editor with JavaScript for a textarea I can check
I am making a WYSIWYG editor using execCommand() and my own drag-and-drop javascript functions.
I'm trying to create a WYSIWYG editor using a div, just like Google Docs
I am making my own WYSIWYG editor. But i can't make any text bold
I am making a simple JavaScript based WYSIWYG editor using regular expressions to do
Making a new site but something is happening to it in IE8. The social

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.