Hi,
I am trying to create my first jQuery script. I want to have a text in
a <p>, select it with the cursor and add a class to it. I know that I
can use the .select and .addClass functions.
$("p").live("mouseup",
function() {
selection = getSelectedText();
if(selection.length >= 3) {
$(this).html($(this).html().addClass("selected");
}
}
);
//Grab selected text
function getSelectedText(){
if(window.getSelection){
return window.getSelection().toString();
}
else if(document.getSelection){
return document.getSelection();
}
else if(document.selection){
return document.selection.createRange().text;
}
}
I can not get this to work.
Thank you.