[Greasemonkey] Find a Selection's Parent Object

Tony Chang tony at ponderer.org
Wed Dec 14 09:58:21 EST 2005


On Wed, Dec 14, 2005 at 11:27:53AM -0500, Tom Clancy wrote:
> I'm guessing this is a solved problem, but I can't turn up anything in a
> search: what's the best (or any) way to find the parent element of a
> highlighted selection on the page?

window.getSelection().getRangeAt(0).commonAncestorContainer ?

"parent" is kind of vague since a selection can span elements.

http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#td-ancestor-container

Tony


-- 
Tony Chang
http://ponderer.org


More information about the Greasemonkey mailing list