Hello,
I have a database which contains a lot of text.
I want to show that text and I did that while iterating over each text with "foreach".
I wanted to add a "show more" button. I did it with this script :
function show_desc() {
var dots = document.getElementById("dots");
var moreText = document.getElementById("more");
var btnText = document.getElementById("myBtn");
if (dots.style.display === "none") {
dots.style.display = "inline";
btnText.innerHTML = "Show Description";
moreText.style.display = "none";
} else {
dots.style.display = "none";
btnText.innerHTML = "Hide Description";
moreText.style.display = "inline";
}
}
</script>
in my html part I have :
@foreach ($items as $item)
<p><span id="dots">...</span><span id="more">{{$item['Description']}}</span></p>
@endforeach
The problem is that the "show more" button only works for the first element. This is because my x items that I show with foreach all get the same "id".
I know the problem but I don't know the solution.
Can anyone help me please