[Javascript] [JavaScript] oElement.topParent()

Mike Dougherty mdougherty at pbp.com
Thu Dec 8 19:50:58 CST 2011


On Wed, Dec 7, 2011 at 8:59 PM, Troy III Ajnej <trojani2000 at hotmail.com> wrote:
>
> Hi there List, I have a question. It sounds
> simple, but it isn't:
> What would be your personal definition of a
> "topParent" property\method of a DOM El?
>
> How would you define it?
>
> For example: a topParent of Input element
> would\should be a Form element...
> But what about other elements including the
> form element if necessary?

If you are using parent as inspired by the existing .parentNode
property and top implying the last element in the upward direction
then I would expect to always end up at document.

If you are limiting this traversal to a logical parent container
element such as the form is a highest-level container for an input,
then I would ask if an arbitrary element should have a topParent of it
nearest/farthest section boundary.  Without a distinction of sections,
you'd be back to document.  If you are considering html5 sectioning
rules, perhaps a "section" element?  Then does a  section also have
section as a topParent?  does the article become topParent to all
contained sections, regardless of nesting depth?

I tried to give it fair consideration.  I don't think adding a
topParent property makes sense in general.  You might have a use for
specific rules in your application and in that case it would work.
However, if you try to make a generic library for parsing any DOM tree
with your topParent property, you'll likely have differences of
opinion on what is the proper implementation.

Do you have more examples of how you were planning to use this
property?  I might have misunderstood your example.


More information about the Javascript mailing list