<div class="post">
<h1>Select Text from the Paragraphs below</h1>
<h2>A circle will appear in the selection position</h2>
<p>This is some text that I want to display and wrap. This is some more text and it's showing up here. This is some text that I want to display and wrap. This is some more text and it's showing up here.</p>
<p>This is some text that I want to display and wrap. This is some more text and it's showing up here. This is some text that I want to display and wrap. This is some more text and it's showing up here.</p>
<p>This is some text that I want to display and wrap. This is some more text and it's showing up here. This is some text that I want to display and wrap. This is some more text and it's showing up here.</p>
<p>This is some text that I want to display and wrap. This is some more text and it's showing up here. This is some text that I want to display and wrap. This is some more text and it's showing up here.</p>
<p>This is some text that I want to display and wrap</p>
<p>This is some text that I want to display and wrap</p>
<p>This is some text that I want to display and wrap</p>
</div>
$(function () {
var markerId = 'tooltip';
$('.post').bind('mouseup', function (e) {
var range, markerEl;
if (document.selection && document.selection.createRange) {
// Clone the TextRange and collapse
range = document.selection.createRange().duplicate();
range.collapse(false);
// Create the marker element containing a single invisible character by creating literal HTML and insert it
range.pasteHTML('<span id="' + markerId + '" />');
} else if (window.getSelection) {
var sel = window.getSelection();
if (sel.getRangeAt) {
range = sel.getRangeAt(0).cloneRange();
} else {
// Older WebKit doesn't have getRangeAt
range.setStart(sel.anchorNode, sel.anchorOffset);
range.setEnd(sel.focusNode, sel.focusOffset);
// Handle the case when the selection was selected backwards (from the end to the start in the
// document)
if (range.collapsed !== sel.isCollapsed) {
range.setStart(sel.focusNode, sel.focusOffset);
range.setEnd(sel.anchorNode, sel.anchorOffset);
}
}
var wordCount = (sel.toString().match(/ /g)||[]).length;
if ( wordCount > 3 ) {
range.collapse(false);
// Create the marker element containing a single invisible character using DOM methods and insert it
markerEl = document.createElement("span");
markerEl.id = markerId;
range.insertNode(markerEl);
}
}
markerEl = $('#' + markerId);
if ( markerEl.length == 1 ) {
markerEl.css({
'position':'absolute',
'display':'none'
}).fadeIn();
/**
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.