SiteKickr Web Development

jQuery nextUntil sluggish

One of jQuery's latest traversal functions, nextUntil, adds enormous value for anyone using expand collapse functionality in their sites.

By allowing you to "select" all elements up until a given element, this short little block of code gives us just about everything we need for expand/collapse:

$('.expand-collapse').children('h3').nextUntil('h3').hide();
$('.expand-collapse').children('h3').click(function() {
    $(this).nextUntil('h3').slideToggle('fast');
});

But, if you find yourself using an older version of jQuery, say 1.4, you mind find that nextUntil function is a little on the "heavy" side in terms of execution time, especially in Internet Explorer 8.0 and prior.

The solution, simple, just upgrade jQuery. I've found the the latest 1.7 branch has greatly improved the execution time.