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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:11:55+00:00 2026-06-12T12:11:55+00:00

I have a problem with contenteditable div. When i want to execute a simple

  • 0

I have a problem with contenteditable div. When i want to execute a simple command (like bold or italic) on it, i do the following:

  • memorize the div (since it will lose focus after i click on bold button)
  • on button click, i refocus the div and execute the bold command
  • everything works

Now the problem occurs when i try to do something more difficult. For instance, i want to show a custom dialog with an input field:

  • memorize the div
  • on button click, a dialog is shown (everything is still ok)
  • user focuses an input field on that dialog (and that’s where everything breaks)

The problem with this is that as soon as an input element is focused, not only that my contenteditable div loses focus – it also loses the selection and moves the cursor to the beginning as soon as i refocus it.

So my question is: how do i prevent a contenteditable div to lose its selection after i focus on another input element?

  • 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-12T12:11:56+00:00Added an answer on June 12, 2026 at 12:11 pm

    If the input and contenteditable element are within the same document, you won’t be able to prevent the selection in the contenteditable element from being destroyed. However, what you can do is save the selection before the input box receives focus and restore the selection after the dialog is dismissed.

    Here is some simple example code:

    https://stackoverflow.com/a/3316483/96100

    And here’s a fuller example:

    https://stackoverflow.com/a/4690057/96100

    If you place either the input or contenteditable element within a separate iframe, most browsers (although not IE) will preserve the original selection.

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

Sidebar

Related Questions

I currently have a simple <div contenteditable=true> working, but, here's my problem. Currently, the
I have problem with this piece of code: var el = $('div#editor'); el.find('*[contentEditable]').removeAttr('contentEditable'); It
I have a contenteditable div, like so: <div id=test contentEditable=true style=width: 600px; height:300px;>Lorem ipsum
I have a contentEditable div with following text for example: <div contentEditable='true'> This document
I'm having trouble using contentEditable in FireFox 3. I have a problem where the
I have a CONTENTEDITABLE div and inside that div I have a CONTENTEDITABLE span,
I have a contenteditable div . Inside, I have put a 'fraction' span, with
Have problem with linq expressions. I want to get from db some data ordered
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem to make work a resource file. This is my simple code

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.