How to go through the cycle based on the parent.

$( ".root > div > div" ).click(function() { var thissku = $(this); //alert(thissku.attr('name')); $(thissku.parent()).each(function(index) { console.log($(this).attr('name')); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="root"> <div class="div-root"> <div name="1">test</div> <div name="2">test</div> <div name="2">test</div> </div> </div> 
why does my .parent() not work?

    1 answer 1

    First of all, you should not wrap it again in jq $ (thissku.parent ()) do so thissku.parent ()

    secondly, you come in a cycle by the parent, and he is alone. Take his children

      thissku.parent().children('div').each(function(index, el) { console.log($(this).attr('name')); }); 
    • Thanks It works. - newProgrammer