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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:39:02+00:00 2026-06-18T15:39:02+00:00

Is the information in this link accurate? https://developer.mozilla.org/en-US/docs/DOM/Selection According to this document: anchorOffset: Returns

  • 0

Is the information in this link accurate?

https://developer.mozilla.org/en-US/docs/DOM/Selection

According to this document:

anchorOffset:
Returns the number of characters that the selection’s anchor is offset within the anchorNode.

Experimentng with FireFox, it seems that definition isn’t always true. Sometimes, the offset properties seem to represent a quantity of childNodes. Based on preliminary tests, the following code works:

var sel = window.getSelection() ;
var points = new Array( 0, 0 ) ;
var offset = new Array( sel.anchorOffset, sel.focusOffset ) ;
var nodes = new Array( sel.anchorNode, sel.focusNode ) ;

if ( isText )
    points = offset ;

for ( j = 0 ; j < 2 && ! isText ; j++ ) {
    var kids = nodes[j].childNodes ;
    for ( var i = 0 ; i < offset[j] ; i++ )
        points[j] += kids[i].textContent.length ;
    }

First, anyone else have this experience? Second, I’m still experimenting trying to find a reliable method to determine the value of isText.

In some respects, this post is partially a question, partially an answer. Hopefully, comments will reflect new details.

  • 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-18T15:39:03+00:00Added an answer on June 18, 2026 at 3:39 pm

    MDN’s definition is wrong [UDPATE: I have corrected MDN now]. anchorOffset and anchorNode (and focusNode and focusOffset) work just like a Range boundary: the offset is a number of characters within a texty node (text, character data and comment nodes) or the number of child nodes of anchorNode preceding the selection anchor in all other node types. In practice, selection boundaries are not always within text nodes, as you’ve observed. An obvious example is when the caret is between two adjacent images (caret represented by a pipe character):

    <div contenteditable="true"><img src="1.png">|<img src="2.png"></div>
    

    Also, Firefox often returns selection boundaries as offsets within elements, especially when a selection selects a whole block element (such as a <p>). Other browsers don’t tend to do this and prefer to return offsets within text nodes.

    As for isText, if I understand you correctly, a full implementation would be something like the following, which is taken from my own code:

    function isCharacterDataNode(node) {
        var t = node.nodeType;
        return t == 3 || t == 4 || t == 8 ; // Text, CDataSection or Comment
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to this link: http://msdn.microsoft.com/en-us/library/live/hh826541.aspx In order to use the Live SDK you have
Specifically: what library is MockObjectTestCase in? I'm following this link: http://therning.org/niklas/2005/05/jmock-solid-testing/ Is there an
I found this link where I got this code: $(document).ready(function(){ //when a link in
I need to get book information from isbndb.com trough XML service using this link
I attempted to run Clean Code according to this link, however nothing is happening.
I try to access information from Twitter and I followed this link: http://code.google.com/p/sociallib/wiki/SocialLibGuide I
How to pass information in this flow: Flash(AS3) -> PHP, using XML -> Database(mysql)
I found some information about this on Scott Hanselmans Blog Does anybody exactly know
For more information see this Example use strict; use warnings; use CGI::Simple; use DBI;
I'm sure this information is available in the C# spec, but I thought I'd

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.