Get div well above the hierarchy [duplicate]

0

I have this hierarchy in HTML

<div class="footer">
            <div class="send_show" style="height: 754px;"></div>
            <div class="forms_sends">
               <span class="sends">
                  <div class="icon-container">
                            <button class="send">ENVIAR</button>

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

and I hope that when the class .send button is clicked, a message appears in send_show . But there are several hierarchies of this on the page, that is, you should get the send_show of the respective button.

I'm using jQuery to accomplish this.

    
asked by anonymous 27.07.2016 / 03:29

1 answer

1

Using parents () to upload to the "parent" div then descends with children () to the "daughter" div you want. So you can have this structure in several places because only the one that is attached to the parent will be affected.

$(".send").on('click', function() {
    $(this)
     .parents(".footer") //Sobe para o pai do evento click
     .children(".send_show") //Desce para a filha
     .html("Div mais próxima");
});

I hope this is it.

    
27.07.2016 / 03:44