How to get the parents siblings content Jquery -


below, code. goal is, when user clicks <a> tag in 'siblings_2'. want alert 'hello' in 'sibling_1' content. how can achieve this?

<div class="parent">     <div class="sibling_1">         <div class="selections">            <p>hello</p>            <p>how you?</p>         </div>     </div>      <div class="sibling_2">         <a href="">click me!</a>     </div> </div> 

you have various ways achieve , 1 way is:

$("div.sibling_2 a").click(function(e) {     e.preventdefault();     var text = $(this).parent().prev().find("div.selections p:eq(0)").text();     alert(text); }) 

demo


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -