May 2017
Intermediate to advanced
448 pages
10h 10m
English
Like any other jQuery object method, traversal methods can be added to jQuery by adding properties to $.fn. We saw in Chapter 8, Developing Plugins, that new jQuery methods we define should operate on the matched set of elements and then return the jQuery object so that users can chain on additional methods. When we create DOM traversal methods, the process is similar, but the jQuery object we return needs to point to a new set of matched elements.
As an example, we'll build a plugin that finds all of the table cells in the same column as a given cell. First we'll look at the plugin code in its entirety, then examine it piece by piece to understand how it works:
(($) => { $.fn.column = function() {Read now
Unlock full access