code_junkie

Is there a way to do a 'scoped' add() in jQuery?

Nov 12th, 2011
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. $(".setA", ancestorOfSetsA);
  2.  
  3. $(".setA", ancestorOfSetsA).add(".setB", ancestorOfSetsB);
  4.  
  5. $(".setA", ancestorOfSetsA).add( $(".setB", ancestorOfSetsB) );
  6.  
  7. $( selector ).add('<div>new element</div>').appendTo( somethere );
  8.  
  9. jQuery.fn.add = function( selector, context ) {
  10. return this.pushStack( jQuery.unique( jQuery.merge(
  11. this.get(),
  12. typeof selector == 'string' ?
  13. jQuery( selector, context ) :
  14. jQuery.makeArray( selector )
  15. )));
  16. }
Add Comment
Please, Sign In to add comment