Change selected text color bg

by yeyene

HTML

<div>
<p>The quick brown fox jumps over the lazy dog</p>
</div>
<br />
<input id="showSelected" type="button" value="showSelected" />

JavaScript

$('#showSelected').on('click', function(){
    
    var text = "";
    if (window.getSelection) {
        text = window.getSelection().toString();
    } else if (document.selection && document.selection.type != "Control") {
        text = document.selection.createRange().text;
    }
    
    alert(text);       
});