как получить элемент соседний родительского 2 уровня jQuery?

нужно получить класс "parent" зная какой либо LI

<div id="accordion">
      <h3 class="parent">{{$category->title}}</h3>
        <div>
             <ul>
                <li><a href="{{url($langSlug .'/products/category/' .$category->slug)}}" class="triangle {{$category->slug}}">All Products {{$category->title}} <span>({{$category->products->count()}})</span></a></li>
                  
                 @foreach($category->children as $category_child)
                    <li>
                        <a href="{{url($langSlug .'/products/category/' .$category_child->slug)}}" class="triangle {{$category_child->slug}}">{{$category_child->title}} <span>({{$category_child->products->count()}})</span></a>
                    </li>

                 @endforeach
                 
                 
             </ul>
        </div>                          
</div>


Ответы (1 шт):

Автор решения: Igor

$("#accordion li").click(function(e){
  var category = $(this).closest("div").prev("h3.parent").text();
  console.log(category);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="accordion">
  <h3 class="parent">Category 1</h3>
  <div>
    <ul>
      <li>One</li>
      <li>Two</li>
      <li>Three</li>
    </ul>
  </div>
  <h3 class="parent">Category 2</h3>
  <div>
    <ul>
      <li>One</li>
      <li>Two</li>
      <li>Three</li>
    </ul>
  </div>
</div>

→ Ссылка