I’m trying to use jQuery to access a DOM object that appears earlier in the code from the DOM object that I am starting with. This would ordinarily be easy with jQuery’s traversal methods, like .parentsUntil. However, in this case the object I am trying to find is not a parent or sibling of the object I am starting from.
For example, imagine this hierarchy:
- table
- tr
- td A
- td B
- tr
- td C
- input D
- td C
- tr
Starting at input D is it possible to find the html() of td A when there could be any number of elements between A and D?
Thanks for your help, and I apologize if this is too vague, I’ll rewrite the question if needed.
I’m not certain what you’re asking (see my comment above). So, assuming you want to find the html content of the
tdof classAthat is closest to elementDwhile also being “above”Din the DOM, you could try something like this:It’s off the top of my head, so there’s probably a more efficient way to do this (and it’s untested), but maybe this gives you some ideas.