When the user selects text I need to check two things before performing my final task:
- Is the selected text within the main .entry-content div? I've done that.
- is the selected text outside or insane any highlighted css class? I need help here.
Basically:
- If "his early familiarity" is selected, return false
- If "head of the first South African Boerboel club" is selected, return true
The HTML source:
<p>
<span id="subject-47" class="subject highlighted">Semencic credits his early familiarity with the breed to his own travels to South Africa<span class="count">4</span></span>, but especially to his frequent correspondence with the head of the first South African Boerboel club, one Mr. Kobus Rust. <strong>The Boerboel Breeders Association was established in 1983</strong> in the Senekal district of the Free State with the sole objective of ennobling and promoting the Boerboel as a unique South African dog breed.
</p>
My Current Javascript (working but I need that last check function)
$( window ).load(function() {
$(document.body).bind('mouseup', function(e){
snapSelectionToWord();
var txt = getHTMLOfSelection();
var contentPos = $('.entry-content').html().indexOf( txt );
if( contentPos > 0 ) {
// do my thing here
// after I check txt IS NOT within a .highlighted css class
}
});
});