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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:09:49+00:00 2026-05-26T20:09:49+00:00

Are there any javascript Rich Text Editors that support getting and setting the cursor

  • 0

Are there any javascript Rich Text Editors that support getting and setting the cursor position?

  • 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-26T20:09:50+00:00Added an answer on May 26, 2026 at 8:09 pm

    I won’t explain the gruesome details, but this will work:

    function getTextNodesIn(node) {
      var textNodes = [];
    
      if (node.nodeType == 3) {
        textNodes.push(node);
      } else {
        var children = node.childNodes;
    
        for (var i = 0, len = children.length; i < len; ++i) {
          textNodes.push.apply(textNodes, getTextNodesIn(children[i]));
        }
      }
    
      return textNodes;
    }
    
    function setSelectionRange(el, start, end) {
      if (document.createRange && window.getSelection) {
        var range = document.createRange();
        range.selectNodeContents(el);
    
        var textNodes = getTextNodesIn(el);
        var foundStart = false;
        var charCount = 0, endCharCount;
    
        for (var i = 0, textNode; textNode = textNodes[i++]; ) {
          endCharCount = charCount + textNode.length;
    
          if (!foundStart && start >= charCount && (start < endCharCount || (start == endCharCount && i < textNodes.length))) {
            range.setStart(textNode, start - charCount);
            foundStart = true;
          }
    
          if (foundStart && end <= endCharCount) {
            range.setEnd(textNode, end - charCount);
            break;
          }
    
          charCount = endCharCount;
        }
    
        var sel = window.getSelection();
    
        sel.removeAllRanges();
        sel.addRange(range);
      } else if (document.selection && document.body.createTextRange) {
        var textRange = document.body.createTextRange();
    
        textRange.moveToElementText(el);
        textRange.collapse(true);
        textRange.moveEnd('character', end);
        textRange.moveStart('character', start);
        textRange.select();
      }
    }
    

    Now you just get your element and select stuff:

    setSelectionRange(document.getElementById('dijitEditorBody'), 10, 50);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any JavaScript or CSS framework that adds CSS3 support to IE6, like
is there any javascript library that provides me with a custom event as soon
Is there any javascript algo that i can used to check for a website
Is there any javascript function that can encrypt data: For example i want to
Is there any javascript(/jquery) framework/plugin which generates Balloons? The one that can be used
Does anyone know of a javascript based Rich Text box that behaves a bit
is there any javascript code that I can use to edit (and maybe download
Is there any javascript, css, ajax product gallery (even paid) that would have image
Is there any JavaScript library that takes Java's SimpleDateFormat pattern and parses a date/time
Is there any javascript library that calculate content-type based on file extension?

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.