jQuery Closest Method - .closest() Tutorial

Read the tutorial on YogiHosting »

1. Click to find the closest 'ul' of span

    div (great-grandparent)
  • ul (second grandparent)
      ul (first grandparent)
    • li (direct parent) span

2. Click to find the closest element with class '.parent', of span inside "DOM"

    div (great-grandparent)
  • Element with id "DOM" (second grandparent)
      ul with class ".parent" (first grandparent)
    • li with class ".parent" (direct parent) span