I think 'previous sibling' is a good term for the element you are
trying to find.

If you put a click handler on the parent of the paragraphs and the
headers, and click on one of the paragraphs, the event.target is that
parent object.  I think you will need to wrap the paragraphs in some
tag, <p> or <span> or something else.  Then, the event.target will be
a specific element, and you can navigate from that with $
(this).prev("h2")

oliver

On Jul 31, 3:40 pm, DaveG <[EMAIL PROTECTED]> wrote:
> I need a way of determining a parent element of the element at the mouse
> position at the time of a double click.
>
> Specifically I'd need to find the 'parent' header (H1, H2, H3, etc)
> based on the DOM element that a user clicks on. Parent in this case
> being the closest header in the stack, since DOM elements are not
> children of header tags.
>
> Thus, in a document structure below, when the user clicks on paragraph
> 2, the h3 DOM element is returned, click on paragraph 3 and the second
> h2 is returned (where paragraphs are any valid DOM elements):
>     <h2>
>     paragraph 1
>
>     <h3>
>     paragraph 2
>
>     <h2>
>     paragraph 3
>
> Thinking about it, I may be able to bind mouse events to all paragraphs,
> and then determine the parent header -- problem there is the text under
> the header could be any valid html, not just paragraphs; alternately
> somehow find the mouse coordinates, and then the DOM element under those
> coordinates...?
>
> Suggestions and alternate approaches appreciated,
>
>   ~ ~ Dave

Reply via email to