Selector jquery with where

0

Hi, I have a problem selecting these divs with jquery and what I want is to select the div of attach_preview row . Until there good. The problem is that I want to take the div that just has the id of the last div that is inside.

Here I show you the HTML:

<div class="attach_preview row">
    <div class="cl_12 row padding_bottom0_5">
        <div class="ftl" id="itemID-OT_5572400-1">

        </div>
    </div>
</div>

These divs are dynamically created with what when creating each one is put with a different id. Already having the code that I pass it in a variable as I can select the first div to empty it and leave it blank.

Greetings and thank you very much.

    
asked by Ruben 13.11.2017 в 14:44
source

2 answers

0

If I have not understood you correctly, you want to select the parent element with the class attach_preview of an element with a id determined.

You can access the "ancestors" of an element in the DOM through the parents jQuery method:

$(function(){
  console.log($('#itemID-OT_5572400-1').parents('.attach_preview')[0]);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="attach_preview row">
    <div class="cl_12 row padding_bottom0_5">
        <div class="ftl" id="itemID-OT_5572400-1">

        </div>
    </div>
</div>
    
answered by 13.11.2017 / 14:53
source
0

If you want to select the last div within cl_12 you can use $('.attach_preview > .cl_12 .ftl:last-child') , but if you do not want to take the class cl_12 as a reference you could do $('.attach_preview').find('.ftl').last() .

    
answered by 13.11.2017 в 16:04