Plugins and utilities
Use $.extend, $.each and data attributes without over-engineering.
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.
$.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
EasyReturn the collection
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 inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.