I have a <textarea>
with say 40 columns. Can i get the left: Xpx;
of a character typed in the <textarea>
. For Example:
<textarea>Hi, my name is Tushar Shukla</textarea>
In this sentence, can i determine what would be the left
of character 'T' in the <textbox>
I don't want to know in what column is my character residing but its distance from the left edge of my textbox!
I have no idea if this is actually possible!!
Any suggestions?
UPDATE
I do not want continuous copy pasting of textarea to a div every time the user presses a key (i'm making this function to run on keyup event).
Asked
Active
Viewed 73 times
2

Tushar Shukla
- 5,666
- 2
- 27
- 41
-
what number of character you want in your textbox. – Ankit Kathiriya Dec 10 '15 at 05:28
-
Do you want Tushar start from left of textarea? or please do more specific. – Chonchol Mahmud Dec 10 '15 at 05:29
-
Is it pretty interesting and it seems to be nearly impossible. There is no native way to do this. What about calculating it yourself - there are too many factors to be included into calculations - font, size, browser-specific things. What is an actual need to do this? – Yeldar Kurmangaliyev Dec 10 '15 at 05:31
-
@AnkitKathiriya There is no specified number of characters i want in textbox. It can be anything that the user types! – Tushar Shukla Dec 10 '15 at 05:39
-
@ChoncholMahmud No, I want to put a `` above the textarea at the position of that character. – Tushar Shukla Dec 10 '15 at 05:40
-
@YeldarKurmangaliyev Why would i calculate it myself, it is meant to be dynamic in respect to what the user will type. ANd yes, there are lot of factors but things like font size can be calculated! – Tushar Shukla Dec 10 '15 at 05:42
-
can you add a FIDDLE showing what you have tried ? – Mayank Dec 10 '15 at 06:24
-
@Mayank Sorry but i' still experimenting so i don't have any solid code to show as of now. But i guess this can be done if put the content before the desired text into a span and calculate its width and then provide the same width as left to my character! Still trying!! – Tushar Shukla Dec 10 '15 at 06:30
-
Why you want to calculate the `left: Xpx;` typed into textarea. Any specific reason ? can you tell me the scenario where you need the above functionality ? – Mayank Dec 10 '15 at 06:41
-
@Mayank As i mentioned in my comment to @ChoncholMahmud above that i want to put a '` tag just at the position of the desired character! – Tushar Shukla Dec 10 '15 at 06:52
-
Possible duplicate of [Get the offset position of the caret in a textarea in pixels](http://stackoverflow.com/questions/16212871/get-the-offset-position-of-the-caret-in-a-textarea-in-pixels) – Sheepy Dec 10 '15 at 09:45