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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:18:03+00:00 2026-06-09T10:18:03+00:00

How to get the cursor position in TinyMCE or the number of line on

  • 0

How to get the cursor position in TinyMCE or the number of line on which the cursor is in TinyMCE?

  • 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-09T10:18:05+00:00Added an answer on June 9, 2026 at 10:18 am

    Here is the part of a function from one of my own plugins i use to get the actual line number:

            var ed = tinymce.get('my_editor_id');
            var bm = ed.selection.getBookmark();
            var $marker = $(ed.getBody()).find('#'+bm.id);
            var elem = ed.getDoc().getElementById(bm.id+'_start');
            try {
                box = elem.getBoundingClientRect();
            } 
            catch(e) 
            {
                                // should not happen
                console.log('error creating box: ' + e);
            }
    
            var doc = ed.getDoc(),
                docElem = doc.documentElement,
                body = ed.getBody(),
                win = ed.getWin(),
                clientTop  = docElem.clientTop  || body.clientTop  || 0,
                clientLeft = docElem.clientLeft || body.clientLeft || 0,
                scrollTop  = win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop  || body.scrollTop,
                scrollLeft = win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft,
                top  = box.top  + scrollTop  - clientTop,
                left = box.left + scrollLeft - clientLeft;
    
            // set Bookmark
            ed.selection.moveToBookmark(bm);
    
            var caret_line = Math.floor( (top) / lineHeight ) + 1;
    

    The function getBoundingClientRect() is used to create a box from which we can get several positioning information. Be aware the we need to use a marker-element and reset the caret later on.

    Update: Info for lineHeight

                // get height of row: eighter line-height or min-height
                if ( $(ed.getBody()).find('p:first').css('line-height') != 'normal'){
                    lineHeight = $(ed.getBody()).find('p:first').css('line-height') ;
                }
                else {
                    lineHeight = $(ed.getBody()).find('p:first').css('min-height');
                }
    
                var lineHeight = lineHeight.substr(0, lineHeight.length -2 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am using selectedTextRange to get a cursor position from my UITextField. I
I want to know how to get the cursor position on Windows in c++,
I can get the actual position of the cursor in an input field. How
I'm trying to get the offset or position of the cursor on a single
I want to get the cursor position of an editable iFrame (using designMode). Here
Is there a way for a Word Add-In to get the current cursor position
I'm trying to get the style/bold,italic,etc/ of the word under the current cursor position.
Assuming the cursor position in a tinymce editor is inside a paragraph. When a
I'm able to get the cursor position with getpos() , but I want to
I can't find out how to get actual drawing cursor position after moveTo(). Check

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.