Guest User

Untitled

a guest
May 26th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. // Instead of using $('div').parent().parent().parent().parent().addClass('lol')
  2. // you can use this: $('div').parentx(4).addClass('lol')
  3.  
  4. if ( window.jQuery ) {
  5. jQuery.fn.parentx = function( i ) {
  6. if ( i > 1 ) {
  7. var e = $(this);
  8. for ( var a = 1; a <= i; a++ ) {
  9. e = e.parent();
  10. }
  11. return e;
  12. }
  13. return $(this).parent();
  14. }
  15. }
Add Comment
Please, Sign In to add comment