Please try not to post multiple messages for the same question, so that people can keep track of a solution.
jQuery is a framework: it eases the pain of cross-browser development and provides shortcuts for DOM manipulation and other common taks. It does that by using the browser methods available, there is no magic in it. getSelection() returns text only, there's nothing jQuery or you or anybody else (except the browser developers) can do about it. I pointed you earlier to the docs on Mozilla Developer Center about the 'selection' object which contains extra information about what is selected on the page. Here's something you can do: sel = window.getSelection(); range = sel.getRangeAt(0); contents = range.cloneContents(); $(contents.childNodes).filter('.dolor') This will give you the element with class "dolor" inside your selection. This only works in Firefox. IE has a different method of doing this (both are non-standard): sel = document.selection; range = sel.createRange(); contents = range.htmlText; Mixing both you get something that is closer to 'cross-browser', I don't know specifically which part of this Webkit supports: function filterSelection(class){ var sel, output; if (window.getSelection) { sel = window.getSelection().getRangeAt(0).cloneContents(); output = $(sel.childNodes).filter(class).text(); } else if (document.selection) { sel = document.selection.createRange().htmlText; output = $(sel).filter(class).text(); }; alert(output); }; I also recommend you to use Firefox + Firebug for development so you can get rid of alert() :) cheers, - ricardo On Dec 2, 6:35 pm, stephane_r <[EMAIL PROTECTED]> wrote: > Hello, > > I'm still a beginner with jQuery (and not really fluent in JavaScript), but > I begin to understand how it works. > > I am trying to move the following code to jQuery: > > var text = window.getSelection(); > alert(text); > > It shows me the currently highlighted part of an xhtml page. Now I want to > use jQuery because it allows me to filter the text according to the class it > is part of, by doing something in the style of: > > $('td.selectable').each(function() { > var text = this.innerHTML; > alert(text); > > }) > > My problem is that I cannot find an equivalent to window.getSelection() in > jQuery, nor use getSelection() with the jQuery objects (once again, beginner > alert, maybe I'm missing something obvious here). > > So, what would you do in order to restrict the returned text to the part of > the DOM that is currently selected (highlighted)? > > Thanks. > -- > View this message in > context:http://www.nabble.com/jQuery-specific-selected-%28highlighted%29-text... > Sent from the jQuery General Discussion mailing list archive at Nabble.com.