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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:37:28+00:00 2026-05-23T19:37:28+00:00

I have a div with contenteditable set. This div contains an inner div like

  • 0

I have a div with contenteditable set. This div contains an inner div like so:

<div contenteditable="true" class="key">
    <div class="innerKey">276</div>
</div>

The odd editable div structure comes about from the need for other functionality.

How would I go about setting the caret position to the start of the content of the inner div using javascript?

  • 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-23T19:37:30+00:00Added an answer on May 23, 2026 at 7:37 pm

    In browsers other than IE < 9, you can do this pretty simply, assuming for brevity that you added an id of “innerKey” to the inner <div>:

    var sel = window.getSelection();
    var innerDiv = document.getElementById("innerKey");
    var innerDivText = innerDiv.firstChild;
    sel.collapse(innerDivText, 0);
    

    jsFiddle: http://jsfiddle.net/Jaj6t/5/

    If you need to support IE < 9, you can use my Rangy library to provide the cross-browser DOM Range and Selection support.

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

Sidebar

Related Questions

have this html: <div id=editable contentEditable=true > <span contentEditable=false >Text to delete</span> </div> need
I have a div element with contenteditable set to true, and I want to
I have a contentEditable div with following text for example: <div contentEditable='true'> This document
I have a contenteditable div, like so: <div id=test contentEditable=true style=width: 600px; height:300px;>Lorem ipsum
I have problem with this piece of code: var el = $('div#editor'); el.find('*[contentEditable]').removeAttr('contentEditable'); It
I have a div with contexteditable set to true and with a special google
I have a div set to contentEditable and styled with white-space:pre so it keeps
Given this editable DIV: <div contenteditable> First line Second line Third line Fourth line
Currently I am making an editor using contenteditable. I have the following: <div contenteditable=true>
I currently have a simple <div contenteditable=true> working, but, here's my problem. Currently, the

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.