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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:32:28+00:00 2026-06-03T06:32:28+00:00

I was wondering wether it was possible to know exactly where in the dom

  • 0

I was wondering wether it was possible to know exactly where in the dom the text that is selected is?

I am currently using the following function to know what text is being selected, but I want to be able to return its position as well

Selector = {};
Selector.getSelected = function(){
  var t = '';
  if(window.getSelection){
    t = window.getSelection();
  }else if(document.getSelection){
    t = document.getSelection();
  }else if(document.selection){
    t = document.selection.createRange().text;
  }
  return t;
}

and I can also find what the parent element is with the following:

function getSelectionStart(){
    var node = document.getSelection().anchorNode;
    var startNode = (node.nodeName == "#text" ? node.parentNode : node);
    return startNode;
}

but is there a way for me to know with js what the character position it has depending on where I click?

  • 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-03T06:32:30+00:00Added an answer on June 3, 2026 at 6:32 am

    I ended up dynamically addressing each character as a seperate span tag and it’s index.

    This is what is currently doing what I want.

    $('#codeinput ul' || '#selectednote li .char').click( function() {
        if ($('#selectednote li *').size() < 2)
        {
        $('#codeinput h1').animate({opacity: '0.6'}, 200);
        inputtype = 1;
        inputnode = '#codeinput #selectednote li'
        console.log('focus is shifted to ' + inputnode)
        $('#codeinput #selectednote li').animate({opacity: '0.9'}, 200);
        }
        else
        {
        $('#selectednote li .char').click(function() {
        k = 0   
        $('#codeinput h1').animate({opacity: '0.6'}, 200);
        var char = $(this).attr('id')
        inputnode = char
        $('#caret').insertAfter('#selectednote li span:eq(' + (parseInt(inputnode) + parseInt(k)) + ')');
        inputtype = 2;
        console.log('clicked on ' + inputnode)
        $('#codeinput #selectednote li').animate({opacity: '0.9'}, 200);
        });
        };
    });
    
    
    
    
    function sendinputtodom(input,type) {
        $(".char").each(function(){ $(this).attr('id', $(this).index())});
    if (inputtype == 2) {
        var from = '#selectednote li span:eq(' + (parseInt(inputnode) + parseInt(k)) + ')';
        console.log(from)
        $('<span class="char">' + input + '</span>').insertAfter(from);
    
        k = k + 1;
    
        $('#caret').insertAfter('#selectednote li span:eq(' + (parseInt(inputnode) + parseInt(k)) + ')');
    
    
        if($('#afterinput').size() < 1)
        {
    
        }
    }
    else
    {
       $('<span class="char">' + input + '</span>').appendTo(inputnode);
    }
    
    $(".char").each(function(){ $(this).attr('id', $(this).index())});
    
    };
    

    It isn’t elegant, clean or light but it gets the job done.

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

Sidebar

Related Questions

I am using annoted Hibernate, and I'm wondering whether the following is possible. I
i was wondering wether it is possible to hold down shift while clicking with
Possible Duplicate: Android ImageButton with a selected state? I was wondering whether there is
I'm currently coding a MEX file that needs to run as quickly as possible
I'm wondering whether it's possible to go back to 2 previous page using navigation
As you all know using java it is possible to create methods which require
I was wondering how I can possible extend XSLT 1.0 so that I can
I was wondering whether it is possible to limit the number of characters we
I am wondering whether it is possible to make dynamic variables in Java. In
I was wondering whether it was possible for projects in Eclipse to have multiple

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.