• Post Reply Bookmark Topic Watch Topic
  • New Topic

findAncestorWithClass() and getParent()  RSS feed

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anybody can tell me what is the difference between findAncestorWithClass() and getParent() ? what situation I should use which one.

Thanks.
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
findParent will return the nearest enclosing tag.

findAncestorWithClass will find the nearest ancestor with the given class. This may be the parent, but likely will not.

i.e. consider basic HTML tags for tables as tag classes.
Table
Tbody
TR
TD

findParent from TD will find the TR it is in. findAncestorWithClass(TR) will find the same TR. findAncestorWithClass(Table) will find the table.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!