Is there a generic way in jQuery or JavaScript (most cross-browser compatible) to check if text has been highlighted?
I am working with an HTML
Based on the above answer, here's the vanilla version.
document.addEventListener('click', function(){
if (window.getSelection().anchorNode.parentElement.classList.contains('word')) {
console.log('highlight');
}
});
I would change 'document' to the wrapping container and 'word' to whatever class/ID is on the text you want to detect a highlight on.