There are dropdown groups for certain links. This is the part of them:
If the li has active-item class under level-1, then i try to replace parent li's close-item with open-item.
This is jquery code for this.
$(document).ready(function() {
$('.active-item').parent('li').addClass('open-item').removeClass('close-item');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li class="has-child-item close-item">
<a><i class="fa fa-cubes" aria-hidden="true"></i><span>İstasyon Ayarları</span></a>
<ul class="nav child-nav level-1">
<li class="active-item"><a href="{{url('/istasyonlar')}}">İstasyon Listesi</a></li>
<li><a href="{{url('/istasyonlar/ekle')}}">Yeni İstasyon Tanımlama</a></li>
</ul>
</li>
But it's not working.
.active-item is not a parent of li it IS the li, you want:
.closest("li.close-item")
Maybe try this :
$('.active-item').parents().closest('li').addClass('open-item').removeClass('close-item');
it will change the closest li
Using closest()
closest() selects the first element that matches the selector, up from the DOM tree.
FYI parent()
parent() selects one element up the DOM tree.
Solution
$(document).ready(function() {
$('.active-item').closest('li.has-child-item').toggleClass('open-item close-item');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li class="has-child-item close-item">
<a><i class="fa fa-cubes" aria-hidden="true"></i><span>İstasyon Ayarları</span></a>
<ul class="nav child-nav level-1">
<li class="active-item"><a href="{{url('/istasyonlar')}}">İstasyon Listesi</a></li>
<li><a href="{{url('/istasyonlar/ekle')}}">Yeni İstasyon Tanımlama</a></li>
</ul>
</li>