Capítulo 142 de 411

Chapter 142: gsap.utils.selector()

Core Idea

selector() returns a query function scoped to a particular element, finding only its descendants — like querySelectorAll() but scoped and returning a real Array.

Key Concepts

  • Returns an Array (not a NodeList), so .filter()/.map() work directly.
  • Accepts a React ref or Angular ElementRef directly — the resulting function auto-resolves .current/.nativeElement even after a re-render.

Code Examples

let q = gsap.utils.selector(myElement); // or ".class"
q(".box"); // Array of .box descendants of myElement

Key Takeaways

  1. The standard pattern for scoping GSAP selectors inside a component instead of querying the whole document.

Connects To

  • gsap.context(): often used together for component-scoped animation setup.