I have two textareas. TA1 which is for styling/display, and TA2 which is for input capture and the ability to place the caret over a span tag. They will always have the same value, but TA1 will contain additional html for styling.
TA1 is overlayed by TA2. Basically, if the textarea is clicked, then TA2 receives the event.
I am trying to select an element in TA1 based off the cursor position in TA2. I know the range of the word that was clicked in TA2, but need to select the appropriate span in TA1. Basically, I need to click through TA2 and trigger the handler in TA1.
I have been trying to see if it's possible to place the caret immediately after the span in TA1, and select the previous span, but so far I have not had any success.
Here is an example of the text within TA1,
<textarea>
<span class=\"suggestion\" title=\"Click to edit\">TESTP</span>\n
\n
123\n
\n
TESTING\n
\n
123\n
\n
<span class=\"suggestion\" title=\"Click to edit\">TESTP</span>
</textarea>
The above html will be rendered into the following..
For example, if I clicked the first "TESTP" I would have a range of 0-4. Is there a way to select the span tag if I placed the caret at position 5 on TA1? I will be trying to see if I can accomplish this using a filter as well but would like to see if anyone has any other suggestions.
I went ahead and created a rough idea of what I am trying to accomplish in this jsFiddle, please note that the textArea on the right is there to display the click handler I am trying to trigger. It works because there isn't another layer above it. The textArea on the left, is where I am currently at.