<div id="text">I am some text, select me and I will show you what you have selected.</div>
<div id="status"></div>
$('#text').on('mouseup', function(ev) {
var selection = $(this).selection(),
text = $(this).text().substring(selection.start, selection.end);
$('#status').html('Selected from ' + selection.start +
" to " + selection.end +
":<br /><span>" + text + "</span>");
});
$('#text').selection(8, 12).trigger('mouseup');
body{
font-family: Helvetica,"Lucida Grande","Lucida Sans",Arial,Helvetica,sans-serif;
}
#text {
padding: 5px;
background-color: #FFFF66;
}
#status {
padding: 10px;
}
#status span {
font-weight: bold;
color: #505050;
}