oliver wrote:
I think 'previous sibling' is a good term for the element you are
trying to find.
Sibling is probably the right term.

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")
Therin lies two challenges.

1] I could put click handlers, but then I'd basically need to add a click handler to *every* DOM element on the page, as they could all be siblings of a heading tag. Probably better to put the click handler on document, and work out what the target was from mouse coords...?

2] Specifying multiple types of tag might be tricky in a consise way, since the statement below doesn't return an ordered list that gets me the very previous sibling:
   $(this).prev("h2, h3, h4, h5")

I guess a simple loop would resolve that though.


The mouse coords seems so clunky though.

 ~ ~ Dave

Reply via email to