I need to highlight the selected text in a div using keys and mouse. Approach for select using mouse is as follows:
html code:
<div id="passage_response" contenteditable="true">
<span class="word" num="0"> In </span>
<span class="word" num="1"> this </span>
<span class="word" num="2"> bug, </span>
<span class="word" num="3"> issue </span>
<span class="word" num="4"> no </span>
<span class="word" num="5"> 1 </span>
<span class="word" num="6"> explains </span>
</div>
jquery:
$('#passage_response .word').bind('dblclick', function() {
toggleHighlight(this);
});
function toggleHighlight(target) {
//highlighting functionality here
}
This is working fine for mouse double click. But for using keys this not working as expected. Because I need to make this functionality accessible to visually impaired people. I tried with keypress and keydown to select the text using keys. But with the .word class it is not returning the object "this". Please someone suggest a solution for this. Thank you