Skip to content
Justice Tech School

Selector Performance

ID selectors are fastest, class selectors next. Cache selections in a variable instead of searching again and again.

Example
const $items = $('.item');
$items.addClass('a');
$items.hide();

Exercise

Cache name starts with ___.

const items = $('.item')

Quiz Test

Why cache a selection?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.