JSFiddle - React, Tailwind, and code Playground

by Turi S

HTML

<p id="targetElement">There is a long sentence here.
The sentence is so long that it overflows from the element.</p>

CSS

#targetElement{
   width:100px;
   height:50px;
   overflow-y:auto;
}

JavaScript

var $elem = $('#targetElement');

function nthCharScroll {
	var text = $elem.html();
  var newText = text.replace(/(#)/, '<span class="get-position-of-it">$1</span>');
  $elem.html(newText); //Set wrapper
  var scrollTop = $(".get-position-of-it").offset();
  //$elem.html(text)    ; //Place back
  var topPos = offset.top;
  var left = offset.left;
  alert(left + ", " + topPos)
}