The code example below does a few simple things. It takes any user-selected text that is in a <p> tag and wraps it in <span> tags and gives that span a class of "hl".
Source: http://esbueno.noahstokes.com/post/92274686/highlight-selected-text-with-jquery