0

Short cut code for to select the 3rd parent of an child element using Jquery. Could you please help me

Ex:

<div>
        <div>
             <div class="child">
             </div>
        </div>
    </div>
JS
    $('.child').parent().parent()

instead of going to this approach, is there any good way to select the parent element in Jquery

1 Answers1

1

Use .eq() with .parents()

$('.child').parents().eq(2);
$('.child').parents().eq(3);

Note: if you use .eq(0), it will return the first level parent.

Anoop Joshi P
  • 25,373
  • 8
  • 32
  • 53