Posted By

thecrumb on 01/23/08


Tagged

jquery


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

martingoldszein
korzhik


jquery - nextUntil


 / Published in: JavaScript
 

Then, your code should look like this ...

$(document).ready(function() { $("dt > a").click(function(){ $(this).parent().nextUntil('dt').toggle(); return false; }); });

  1. /******** next until > ****************/
  2. $.fn.nextUntil = function(expr) {
  3. var match = [];
  4.  
  5. // We need to figure out which elements to push onto the array
  6. this.each(function(){
  7. // Traverse through the sibling nodes
  8. for( var i = this.nextSibling; i; i = i.nextSibling ) {
  9. // Make sure that we're only dealing with elements
  10. if ( i.nodeType != 1 ) continue;
  11.  
  12. // If we find a match then we need to stop
  13. if ( jQuery.filter( expr, [i] ).r.length ) break;
  14.  
  15. // Otherwise, add it on to the stack
  16. match.push( i );
  17. }
  18. });
  19.  
  20. return this.pushStack( match, arguments );
  21. };
  22.  
  23. /******** < next until ****************/

Report this snippet  

You need to login to post a comment.