Reputation: 1339
This is my html:
<div class="popup" onclick="itemPopup()">
<img src="{{$item->item->img}}">
<span class="popuptext" id="myPopup">
{{$item->title}}<br>
<a href="/sell-item/{{$item->id}}" class="btn-sm btn-danger" style="text-decoration: none">
Sell for {{$item->price/2}} <img src="/img/gold.png"></a><br>
<p>{{$item->description}}</p>
</span>
</div>
@endforeach
This is my js:
function itemPopup() {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}
When I click on image the pop up shows like this:
No matter if I click on second sword, the pop up box will still appear on first sword with his id
. How to fix this issue ?
Upvotes: 0
Views: 88
Reputation: 389
Assign unique ids to each iteration of your blade and then pass that same ID in the JavaScript function call. Your HTML will look like this.
<div class="popup" onclick="itemPopup('myPopup{{$item->id}}')">
<img src="{{$item->item->img}}">
<span class="popuptext" id="myPopup{{$item->id}}">
{{$item->title}}<br>
<a href="/sell-item/{{$item->id}}" class="btn-sm btn-danger" style="text-decoration: none">
Sell for {{$item->price/2}} <img src="/img/gold.png"></a><br>
<p>{{$item->description}}</p>
</span>
</div>
And the JavaScript:
function itemPopup(ID) {
var popup = document.getElementById(ID);
popup.classList.toggle("show");
}
Upvotes: 1