Is there any event listener for highlight event in HTML using JavaScript (sort of onHighlight)? Is it possible to get the text highlighted?
Is there any event listener for highlight event in HTML using JavaScript (sort of
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try the following:
All browsers (except for IE <9) support
window.getSelection(); IE <9 supportsdocument.selection.createRange().text.The function can be attached to
onmouseup, if you wish to support mouse-based selection, oronkeyup, if you wish to support keyboard-based selection.As Robby Shaw mentions below, QuirksMode’s Introduction to Range is fairly useful for understanding
Rangeobjects, which this code is based off.