I'm attempting to write a JavaScript tool to let my users compare ranges of characters in slightly varied text strings. It's critical that the users still be able to select that text.
# || is a section my tool highlights. The number of characters the highlight covers starts at one, but can be varied by text selection.
Foo |Bar Baz Quux|
Foo |Bra Biz Quix|
At present, a div contains a table. A secondary div is inside the first, and a third div is inside the second.
The second div overlies the text in the table, while the third is the div that actually appears semi-opaque over the text that the user wants to examine.
<div>
<div class="text-cell-area">
<div class="highlighter"></div>
</div>
<table>
<tr><td>text</td></tr>
<tr><td>text</td></tr>
</table>
</div>
On page load, I use JavaScript to modify .text-cell-area
such that its offsets and dimensions completely cover all the text whose alignment I need to check; it's basically a box floating over several table rows.
Mouseover events and window.onmousemove track the user's cursor, setting the location of .highlighter
to match the location of the user's cursor and snap to each monospaced character.
This functionality is fine - Alignment checking works perfectly. The problem is that I now have two divs overlying the text in my table so that I can't select it. I can't use pointer-events: none;
to allow my users to the select the text because that prevents the mouseover event from tracking the user's cursor to set the location of the highlighting div.
What I need is a different way to allow my users to select the text underneath both divs. How might I do that?