0

I am creating a markdown editor, where you write in the left column, and the result is shown in the right column. Similar to SO's markdown editor.

The problem is that when your texts get long, you cannot see the result anymore because it is too far down and out of the viewport.

I can get the current cursor position within the textarea. I can also get the text within the div element and strip it of HTML tags.

Is there a way to scroll a div to its nth character, without setting any anchors?

EDIT: I am not looking for a way to make the page scrollable. I am asking if it is possible to scroll to a specific position within the text of a div element without setting anchors around every word. Is it even possible?

EDIT2: @Cbroe is exactly right. My question indeed becomes: How can I figure out where on my page a certain character is?

Marco7757
  • 635
  • 7
  • 15
  • Possible duplicate of [Make text scrollable within div](https://stackoverflow.com/questions/24917983/make-text-scrollable-within-div) – Waleed Iqbal Mar 02 '18 at 07:49
  • I am not looking for a way to make the div scrollable. The entire page is already scrollable. I am asking to find a way to scroll the a specific position within the text of the div. – Marco7757 Mar 02 '18 at 07:58
  • Without anchors, you could only scroll to a specific pixel position. So your question then becomes, how do you determine at what position a specific character is shown ... – CBroe Mar 02 '18 at 08:03

1 Answers1

1

Hey if you use jquery you can use $("#item").scrollTo function in Jquery.

$('div').scrollTo('#target'); // Scroll screen to target element

$('body').scrollTo(500); // Scroll screen 500 pixels down

$('#scrollable').scrollTo(100); // Scroll individual element 100 pixels down

Owner of this code up here

To scroll in div just select div. For nth just use ccs selector in second jquery selector.

After that if you have a problem with making your div scrollable you can use css for that.

#divItem{ overflow-y:scroll; height:600px; }

You need height for so it will know where it should stop expanding.

Edit after edit:Jus tuse .position in Jquery

mertselimb
  • 157
  • 7