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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:00:05+00:00 2026-06-04T14:00:05+00:00

I am using great Rangy library . And I am also using Tim Down’s

  • 0

I am using great Rangy library. And I am also using Tim Down’s function for inserting HTML node into contenteditable DIV:

function insertNodeAtCaret(node) {
    var sel = rangy.getSelection();
    if (sel.rangeCount) {
        var range = sel.getRangeAt(0);
        range.collapse(false);
        range.insertNode(node);
        range.collapseAfter(node);
        sel.setSingleRange(range);
    }
}

Now, this works fine and as expected in Chrome. However there is different behaviour in FF and Opera. In Chrome, the HTML node is inserted in contenteditable and the caret stays in this HTML node so when user continues typing, all his typing is inside inserted HTML node.

In Opera and Firefox, the caret is placed outside of inserted HTML node and when user continues typing, the typed characters are NOT inside HTML node.

My code expects “Chrome way” of working. Can you please help me to achieve the same behaviour in FF and Opera ?

Working jsFiddle for testing is here: http://jsfiddle.net/Er5DH/2/ (when you press “x” key in contenteditable, it inserts SPAN element with red color. In Chrome when you continue typing the characters are red, as expected. But in FF and Opera, the next typed letters after “x” key press are black – not wanted)

Thanks for any help and hints.

  • 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-04T14:00:07+00:00Added an answer on June 4, 2026 at 2:00 pm

    You could change range.collapseAfter(node) to

    range.selectNodeContents(node);
    range.collapse(false);
    

    See http://jsfiddle.net/Er5DH/6/

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

Sidebar

Related Questions

I had an old (but great) app using NHibernate 1.0.2. Worked like a charm.
Using cURL_multi is great for simultaneous connections, but what can limit the number of
I'm using XSLT and having great success, just got a couple of problems. Warning:
I have been using this code with great success to pull out the first
I'm using astyle which is great for applying standard style to existing code. However
iam using AVFoundation Framework to play mp3 file ,everything works great ، i have
Im using jsoncpp , its great but when i need to check if json
I am using cluetip plugin which is great. I am populating the plugin using
I am using the following which works great. I am just wondering if it
I am using Twitterizer which works great. I have a website (.NET 4, C#)

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.