Monday 3 December 2012

jquery Everything “until”!

Three new methods have been added to the DOM traversal arsenal in 1.4, "nextUntil", "prevUntil" and "parentsUntil". Each of these methods will traverse the DOM in a certain direction until the passed selector is satisfied. So, let’s say you have a list of fruit:



  1. <ul>  
  2.     <li>Apple</li>  
  3.     <li>Banana</li>  
  4.     <li>Grape</li>  
  5.     <li>Strawberry</li>  
  6.     <li>Pear</li>  
  7.     <li>Peach</li>  
  8. </ul>
 You want to select all of items after "Apple", but you want to stop once you reach "Strawberry". It couldn’t be simpler:


  1.  jQuery('ul li:contains(Apple)').nextUntil(':contains(Pear)'); 

No comments:

Post a Comment