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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:38:53+00:00 2026-06-15T00:38:53+00:00

I am using a Range object as a limiter on another Range object representing

  • 0

I am using a Range object as a limiter on another Range object representing the current selection, such that anything that is inside the selected range but is outside the boundaries of the limiting range is trimmed off. To compare the two Ranges’ positions, I’m using the Range.compareBoundaryPoints() function, but the results make no sense.

The element I’m working with looks like this:

<p id="myBlock" contenteditable="true">
  Hello hello hello, this is a great big block of test text.
</p>

The ranges are defined and their positional relationship retrieved as follows:

var limitingRange = document.createRange();
limitingRange.selectNodeContents($('#myBlock')[0]);
var selectedRange = window.getSelection().getRangeAt(0).cloneRange(); //Use whatever method is supported by the browser to get the Range

var endToStart = limitingRange.compareBoundaryPoints(Range.END_TO_START, selectedRange);
var startToEnd = limitingRange.compareBoundaryPoints(Range.START_TO_END, selectedRange);
var startToStart = limitingRange.compareBoundaryPoints(Range.START_TO_START, selectedRange);
var endToEnd = limitingRange.compareBoundaryPoints(Range.END_TO_END, selectedRange);

I then select the word “this” in the text and run the function. My ranges look like this (I’m inventing the .start and .end notation to try and make my description clearer):

(limitingRange.start)Hello hello hello, (selectedRange.start)this(selectedRange.end) is a great big block of test text.(limitingRange.end)

The resulting values are:

endToStart = -1

startToEnd = 1

startToStart = -1

endToEnd = 1

I am baffled as to how to interpret the results of the function. Based on the specification it seems like, for example, endToStart should contain -1 if the end of selectedRange comes before the start of limitingRange, but that’s obviously not the case. What’s going on here?

  • 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-15T00:38:55+00:00Added an answer on June 15, 2026 at 12:38 am

    I’m answering my own question: Typing out what was going on led me to actually understand the function’s behavior, which really is strange.

    The result of a.compareBoundaryPoints(X_TO_Y, b) is the comparison of a.Y to b.X. -1 if a.Y comes before b.X, 0 if they are at the same position, and 1 if it comes after.

    So in endToStart in the above example, limitingRange.start is being compared to selectedRange.end, with -1 indicating that limitingRange.start comes first.

    startToEnd: limitingRange.end comes after selectedRange.start, so the result is 1.

    startToStart: limitingRange.start comes before selectedRange.start, so the result is -1.

    endToEnd: limitingRange.end comes after selectedRange.end, so the result is 1

    Leaving me with only the question: Why does this function behave this way? The names of the constants are the opposite of what one would intuitively expect.

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

Sidebar

Related Questions

When using Excel Interop libraries from .NET, I can find a Range object representing
Using this C# application pick a start and ending date range, that SAP will
I have a range of data that I have approximated using a polynomial of
First I was using this request: Model.object.get(name='something', date=somedatavariable) But then I needed to extend
I'm building a generic UI that can hook into a range of underlying object
I am using a grid system to determine an object's adjacency to another. I'm
When using the triple dot notation in a ruby Range object, I get this:
I create a Range object and then add this Range to selection window.getSelection ().addRange(myRange);
I usually either end up using [range]%s/word/another_word/gc or do it manually. I wonder if
Is there a way of using the range() function with stride -1? E.g. using

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.