jQuery·jQuery from selection to migration

Plugins and utilities

Use $.extend, $.each and data attributes without over-engineering.

Beginner 12 min read Lesson 8 of 300 Challenge included
What you will be able to do
  • Plugins should return the collection.
  • Use $.extend for defaults and deep copies.
  • Store instance data with .data().
  • Clean up handlers and timers on destroy.

In plain English

jQuery plugins extend $.fn and are chained like built-in methods. Utilities such as $.extend copy objects and $.each iterates. Prefer small, single-purpose plugins and avoid global state.

plugin.jsJavaScript
$.fn.highlight = function (options) {
  const settings = $.extend({ color: '#ffe08a' }, options)
  return this.each(function () {
    $(this).css('background-color', settings.color)
  })
}

$('.row').highlight({ color: '#eef6ff' })
Your turn

Return the collection

Easy

Make a plugin return this.each(...).

JAVASCRIPT · starter
function () { }
Check your understanding before moving on.
Knowledge checkQuestion 1

What should a jQuery plugin return to support chaining?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 8 of 300 · 0% of course