when I click on a profile in the foreach loop, the "active" property of all "active" classes is deleted, not just the profile I clicked. How can I fix it so that only what I click is deleted? I do not want all "active" classes to be deleted, but only the active class property you clicked.
@foreach($other_user['details'] as $user)
@php
$user_id = Auth::user()->id;
$withid= $user->id;
$getunreadcount = \Models\Members::getlastconverunread($user_id,$withid);
@endphp
<a href="javascript:void(0);" data-conversation="{{$user->lastConver != null ? 'true' :'false'}}" data-id="{{ $user->username }}" @if($getunreadcount > 0) @else @endif >
<div >
@if($user->user_photo!='')
<img src="{{ url('/') }}/public/storage/users/{{ $user->user_photo }}" alt="{{ $user->username }}" width="40" height="40">
@else
<img width="40" height="40" src="{{ url('/') }}/public/img/no-user.png" alt="{{ $user->username }}" />
@endif
<div >
<span >
{{ $user->username }}
</span>
@if($getunreadcount > 0)
<div ><span >{{$getunreadcount}} Yeni Mesaj</span></div>
@endif
</div>
</div>
</a>
@endforeach
JQUERY:
$('.userlink').click(function(e) {
e.preventDefault();
var id = $(this).data("id");
var token = $("meta[name='csrf-token']").attr("content");
$('.userlink').removeClass('active');
var $this = $(this);
if (!$this.hasClass('active')) {
$this.removeClass('active');
}
});
I will be glad if you help me thank you.
CodePudding user response:
$('.userlink').click(function(e) {
e.preventDefault();
...
// Like this:
$(this).removeClass('active');
});