May 2017
Intermediate to advanced
448 pages
10h 10m
English
We have used chaining many times now, and it has allowed us to keep our code concise. There can be a performance benefit to chaining as well.
Our stripe() function from Listing 9.9 located the element with the ID news once instead of twice. It needed to remove the alt class from rows that no longer needed it, and to apply that class to the new set of rows. Using chaining, we combined these two thoughts into one and prevented this repetition:
$(() => { function stripe() { $('#news') .find('tr.alt') .removeClass('alt') .end() .find('tbody') .each((i, element) => { $(element) .children(':visible') .has('td') .filter(':group(3)') .addClass('alt'); }); } stripe();});
In order to merge the two ...
Read now
Unlock full access