I have a loop:
$(document).ready(function(){
$(".viewonclick").click(function(){
$(this).closest('.viewonclick').next(".hideonclick").slideToggle();
$(".plus").toggleClass("hideplus");
});
});
.viewonclick i{
position : absolute;
right: 220px;
display: inline;
}
.viewonclick .hideplus{
display: none;
}
@foreach($customcat as $c)
<div>
<div class="viewonclick"><h4>{{ $c->Custom->name }}
<i class="plus icon"></i>
<i class="minus icon"></i>
</h4></div>
<ul class="hideonclick">
@foreach($customvalue as $v)
<li>
@if($v->custom_id == $c->custom_id)
<a class="customcatvalue" data-customid="{{$c->custom_id}}" data-valueid="{{$v->id}}" data-section="{{ $section->id }}">
{{ $v->value }}
</a>
@endif
</li>
@endforeach
</ul>
</div>
@endforeach
When the loop works all elements having the class plus are changed to have hideplus instead. I only need the clicked element to take this class. I tried the .next() and .closest() method. It worked with .slideToggle() but not with .toggleClass().