I am creating a test and I want a highlighter feature so that students can highlight important points while reading a paragraph. I am using jquery for this and my code is
$('.panel-one').on('mouseup',function getSelectionText() { var text = ""; if (window.getSelection) { text = window.getSelection().toString(); } else if (document.selection && document.selection.type != "Control") { text = document.selection.createRange().text; } console.log(text); }) I want to create a button (floating with cursor after selection) to highlight the selected text which is coming out on the console for which I have to wrap the text with a div. and also delete the highlight (removing the div) using the same method.
here is the website which is using this exact same feature (creating the same type of test). I don't want different color but highlighting and deleting highlighting https://ieltsonlinetests.com/ielts-mock-test-2021-january-reading-practice-test-1
I do try it with .wrap and wrapping the "text" variable but no luck.
if you need any other info pls let me know
.text()then split/splice/substr/substring to the end of your selection, insert</span>there and do the same for the start of the selection<span class='highlight'>- then put the text back using.html(updated_text)