Tuesday, June 30, 2009

[jQuery] Re: Howto detect DOM element from selected text

not sure you've explained what it is you are trying to do

are you trying to work with "John" and create a selector/method to do it?

Alexander wrote:
Hi there !  I'm stuck with a problem and hope someone can give me the right hint. I am trying to detect the DOM element on a unkown web page  from the current selected text on that page.  Which means: I select text on a web page and then I would like to get the dom element to which this text belongs.  What I came up with was something like that:   (imagin we selected the word John on that page....)  var array = $("*:contains('John')");            ---> get all dom elements that contain the text 'John'   But, instead of returning all dom elements that contain 'John' , it returns only the path from the HTML element to the P element that contains the text 'John'.  (HTML->Body->P)  Did I miss something ? Is there a complete different way to accomplish what I want ?   Thanks and good bye,  Alexander     

No comments: